Created
December 14, 2011 20:12
-
-
Save munro/1478276 to your computer and use it in GitHub Desktop.
Lambda Speed Comparison
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 | |
print 'Lambda: %f' % timeit.Timer('fn = lambda x: x * x\n' | |
'map(fn, xrange(10))', 'gc.enable()').timeit() | |
print 'Named function: %f' % timeit.Timer('def fn(x): return x * x;\n' | |
'map(fn, xrange(10))', 'gc.enable()').timeit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
✲ python speed.py
Lambda: 2.083640
Named function: 2.083197
why is this so slow!?