-
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.
Fix for long
add_gtfs_headways
calls (#55)
* wip * working but still not a huge jump in performance * ready to go? * commented out code * reset state.json on GTFS change * Update src/gobble.py Co-authored-by: Devin Matte <[email protected]> --------- Co-authored-by: Devin Matte <[email protected]>
- Loading branch information
1 parent
eeb3a2a
commit b75f9a1
Showing
4 changed files
with
140 additions
and
64 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
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,30 @@ | ||
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 |