Skip to content

Commit 90d91be

Browse files
authored
Create timethis
1 parent e0d2e4f commit 90d91be

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

timethis

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from timeit import default_timer as timer
2+
from functools import wraps
3+
4+
5+
def timethis(func):
6+
@wraps(func)
7+
def wrapper(*args, **kwargs):
8+
start = timer()
9+
r = func(*args, **kwargs)
10+
end = timer()
11+
print('{}.{} : {}'.format(func.__module__, func.__name__, end-start))
12+
return r
13+
return wrapper
14+
15+
16+
if __name__ == '__main__':
17+
@timethis
18+
def countdown(n):
19+
while n > 0:
20+
n -= 1
21+
22+
23+
countdown(10000000)

0 commit comments

Comments
 (0)