Last active
August 29, 2015 14:22
-
-
Save Veedrac/c343f3c2b0a2a563658a to your computer and use it in GitHub Desktop.
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
>>> python2 -m timeit -s 'r = {1, 2, 3}; s = {4, 5, 6}; t = {7, 8, 9}' '3 in reduce(lambda x,y :x.union(y),[r,s,t])' | |
1000000 loops, best of 3: 1.01 usec per loop | |
>>> python2 -m timeit -s 'r = {1, 2, 3}; s = {4, 5, 6}; t = {7, 8, 9}' '3 in r|s|t' | |
1000000 loops, best of 3: 0.399 usec per loop | |
>>> python2 -m timeit -s 'r = {1, 2, 3}; s = {4, 5, 6}; t = {7, 8, 9}' '3 in set().union(r, s, t)' | |
1000000 loops, best of 3: 0.407 usec per loop | |
>>> python2 -m timeit -s 'r = {1, 2, 3}; s = {4, 5, 6}; t = {7, 8, 9}' 'any(3 in item for item in [r,s,t])' | |
1000000 loops, best of 3: 0.621 usec per loop | |
>>> python2 -m timeit -s 'r = {1, 2, 3}; s = {4, 5, 6}; t = {7, 8, 9}' '3 in r.union(s).union(t)' | |
1000000 loops, best of 3: 0.528 usec per loop |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment