Spaces:
Runtime error
Runtime error
fix calc fct for inference time
Browse files
utils.py
CHANGED
|
@@ -6,18 +6,22 @@ Author:
|
|
| 6 |
- @ChainYo - https://github.com/ChainYo
|
| 7 |
"""
|
| 8 |
|
|
|
|
| 9 |
from time import time
|
|
|
|
| 10 |
|
| 11 |
|
| 12 |
-
|
| 13 |
-
|
|
|
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
start = time()
|
| 18 |
-
result = func(*args, **kwargs)
|
| 19 |
-
end = time()
|
| 20 |
-
print(f"{func.__name__} took {end - start:.2f} seconds.")
|
| 21 |
-
return result
|
| 22 |
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
- @ChainYo - https://github.com/ChainYo
|
| 7 |
"""
|
| 8 |
|
| 9 |
+
from contextlib import contextmanager
|
| 10 |
from time import time
|
| 11 |
+
from typing import List
|
| 12 |
|
| 13 |
|
| 14 |
+
@contextmanager
|
| 15 |
+
def calculate_inference_time(buffer: List[int]):
|
| 16 |
+
"""Calculate inference time.
|
| 17 |
|
| 18 |
+
Args:
|
| 19 |
+
buffer (list): List of inference times.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
+
Returns:
|
| 22 |
+
float: Average inference time.
|
| 23 |
+
"""
|
| 24 |
+
start = time()
|
| 25 |
+
yield
|
| 26 |
+
end = time()
|
| 27 |
+
buffer.append(end - start)
|