Last active
February 20, 2017 08:58
-
-
Save emiel/7afbf7fccb20eb831011864139b25922 to your computer and use it in GitHub Desktop.
Python nested function overhead
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
import timeit | |
t1 = timeit.Timer("doit()", """ | |
def doit(): | |
def foo(l): | |
return [x**2 for x in l] | |
def bar(l): | |
return [x**2 for x in l] | |
l = [x for x in range(1000)] | |
foo(l) | |
bar(l) | |
""") | |
t2 = timeit.Timer("doit()", """ | |
def foo(l): | |
return [x**2 for x in l] | |
def bar(l): | |
return [x**2 for x in l] | |
def doit(): | |
l = [x for x in range(1000)] | |
foo(l) | |
bar(l) | |
""") | |
print(t2.repeat(10, 1000)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment