Skip to content

Instantly share code, notes, and snippets.

@munro
Created December 14, 2011 20:12
Show Gist options
  • Save munro/1478276 to your computer and use it in GitHub Desktop.
Save munro/1478276 to your computer and use it in GitHub Desktop.
Lambda Speed Comparison
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()
@munro
Copy link
Author

munro commented Dec 14, 2011

✲ python speed.py
Lambda: 2.083640
Named function: 2.083197

why is this so slow!?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment