Skip to content

Instantly share code, notes, and snippets.

@aj-justo
Created August 1, 2012 12:11
Show Gist options
  • Save aj-justo/3226316 to your computer and use it in GitHub Desktop.
Save aj-justo/3226316 to your computer and use it in GitHub Desktop.
"timeits" with python 2.7.2 on OSX

Filter out None values from list

>>> timeit.Timer("[x for x in [1,2,3,None] if x]").timeit()
0.7186648845672607

>>> timeit.Timer("filter(None, [1,2,3,None])").timeit()
0.5820250511169434

Apply a function to every element on list

>>> timeit.Timer('[int(x) for x in ["1","2","3","4","5"]]').timeit()
3.578153133392334

>>> timeit.Timer('map(int,["1","2","3","4","5"])').timeit()
4.9065070152282715

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