chainyo commited on
Commit
87e8a82
·
1 Parent(s): 823b1a5

fix calc fct for inference time

Browse files
Files changed (1) hide show
  1. utils.py +14 -10
utils.py CHANGED
@@ -6,18 +6,22 @@ Author:
6
  - @ChainYo - https://github.com/ChainYo
7
  """
8
 
 
9
  from time import time
 
10
 
11
 
12
- def timeit(func):
13
- """Timeit decorator."""
 
14
 
15
- def wrapper(*args, **kwargs):
16
- """Wrapper."""
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
- return wrapper
 
 
 
 
 
 
 
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)