-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
working but still not a huge jump in performance
- Loading branch information
Showing
3 changed files
with
43 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from functools import wraps | ||
from time import time | ||
from random import random | ||
import numpy as np | ||
|
||
|
||
def measure_time(report_frequency: float = 1.0, trail_length=1000): | ||
def decorator(fn): | ||
exec_times = [] | ||
@wraps(fn) | ||
def wrap(*args, **kw): | ||
nonlocal exec_times | ||
ts = time() | ||
result = fn(*args, **kw) | ||
te = time() | ||
exec_times.append(te - ts) | ||
if random() < report_frequency: | ||
last = exec_times[-1] | ||
exec_times = exec_times[-trail_length:] | ||
avg = np.mean(exec_times) | ||
std = np.std(exec_times) | ||
min = np.min(exec_times) | ||
max = np.max(exec_times) | ||
print(f"func {fn.__name__}: last={last:.3f}s min={min:.3f} max={max:.3f} avg={avg:.3f}s std={std:.3f}s") | ||
return result | ||
|
||
return wrap | ||
|
||
return decorator |