Better handling of time
This commit is contained in:
parent
b5c4004959
commit
78abb7a5e8
@ -5,14 +5,26 @@ from functools import wraps
|
|||||||
def timeit(name):
|
def timeit(name):
|
||||||
def profile(original):
|
def profile(original):
|
||||||
import time
|
import time
|
||||||
|
|
||||||
@wraps(original)
|
@wraps(original)
|
||||||
def wrapper(*args, **kwargs):
|
def wrapper(*args, **kwargs):
|
||||||
t0 = time.perf_counter()
|
t0 = time.perf_counter()
|
||||||
result = original(*args, **kwargs)
|
result = original(*args, **kwargs)
|
||||||
t1 = time.perf_counter()
|
t1 = time.perf_counter()
|
||||||
print(f"Time to evaluate problem {int(name[7:]):003d}: {(t1 - t0)*1000:.3f} ms\n")
|
if (t1 - t0) > 1:
|
||||||
|
print(
|
||||||
|
f"Time to evaluate problem {int(name[7:]):003d}: "
|
||||||
|
f"{(t1 - t0):.3f} s\n"
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
print(
|
||||||
|
f"Time to evaluate problem {int(name[7:]):003d}: "
|
||||||
|
f"{(t1 - t0)*1000:.3f} ms\n"
|
||||||
|
)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
return profile
|
return profile
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user