Skip to content

Instantly share code, notes, and snippets.

@bjmc
Created August 29, 2013 20:49
Show Gist options
  • Save bjmc/6383230 to your computer and use it in GitHub Desktop.
Save bjmc/6383230 to your computer and use it in GitHub Desktop.
import cProfile
cProfile.run("""
f = lambda x: x*2
for i in xrange(10000000):
f(i)
""")
cProfile.run("""
f = lambda x: x*2
[f(i) for i in xrange(10000000)]
""")
cProfile.run("""
f = lambda x: x*2
map(f, xrange(10000000))
""")
x$ python temp1.py
10000002 function calls in 2.087 seconds
Ordered by: standard name
ncalls tottime percall cumtime percall filename:lineno(function)
10000000 0.647 0.000 0.647 0.000 <string>:2(<lambda>)
1 1.440 1.440 2.087 2.087 <string>:2(<module>)
1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}
10000002 function calls in 2.214 seconds
Ordered by: standard name
ncalls tottime percall cumtime percall filename:lineno(function)
10000000 0.651 0.000 0.651 0.000 <string>:2(<lambda>)
1 1.562 1.562 2.214 2.214 <string>:2(<module>)
1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}
10000003 function calls in 1.876 seconds
Ordered by: standard name
ncalls tottime percall cumtime percall filename:lineno(function)
10000000 0.697 0.000 0.697 0.000 <string>:2(<lambda>)
1 0.058 0.058 1.876 1.876 <string>:2(<module>)
1 1.122 1.122 1.818 1.818 {map}
1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment