Created
February 21, 2012 23:26
-
-
Save bukzor/1879776 to your computer and use it in GitHub Desktop.
Demonstrate difficulty with profiling and decorators
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
from time import sleep | |
def decorator(func): | |
def wrapper(*args, **kwargs): | |
return func(*args, **kwargs) | |
wrapper.__name__ += '_' + func.__name__ | |
return wrapper | |
@decorator | |
def d1(): | |
sleep(1) | |
@decorator | |
def d2(): | |
sleep(.2) | |
@decorator | |
def d3(): | |
sleep(.03) | |
def f1(): | |
d1() | |
d2() | |
f2() | |
def f2(): | |
d2() | |
d3() | |
d3() | |
def f3(): | |
f1() | |
f2() | |
d3() | |
if __name__ == '__main__': | |
f1() | |
f2() | |
f3() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment