Add timing decorator

This commit is contained in:
daniele 2023-06-07 17:10:51 +02:00
parent ef2d0423c2
commit b46ae4e387
Signed by: fuxino
GPG Key ID: 981A2B2A3BBF5514

View File

@ -1,6 +1,8 @@
#!/usr/bin/env python3
from functools import wraps
from math import sqrt, floor, ceil, gcd
from timeit import default_timer
from numpy import zeros
@ -495,3 +497,17 @@ def dijkstra(matrix, distances, m, n, up=False, back=False, start=0):
if i == m - 1 and j == n - 1:
break
def timing(f):
@wraps(f)
def wrapper(*args, **kwargs):
start = default_timer()
result = f(*args, **kwargs)
end = default_timer()
print(f'{f.__name__!r} took {end - start:.9f} seconds')
return result
return wrapper