Created
April 6, 2014 08:40
-
-
Save sapamja/10003182 to your computer and use it in GitHub Desktop.
comparing function return assigning variable vs not.
This file contains hidden or 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
#!/usr/bin/python | |
from memory_profiler import profile | |
@profile | |
def func1(a): | |
if a > 0: | |
num = 1 | |
else: | |
num = -1 | |
return num | |
#@profile | |
def func2(a): | |
if a > 0: | |
return 1 | |
else: | |
return -1 | |
func = [ func1, func2 ] | |
import cProfile | |
from timeit import Timer | |
import dis | |
for fun in func: | |
print fun(100) | |
t = Timer(lambda: fun(-1)) | |
print fun.__name__, cProfile.run('t.timeit(number=1000)') | |
print fun.__name__ | |
print dis.dis(fun) | |
print '-------' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment