Created
March 29, 2016 10:15
-
-
Save brendan-donegan/3ae26694db7edac26e73 to your computer and use it in GitHub Desktop.
in set vs in list
This file contains hidden or 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
brendand@brendand-T450:~$ cat algo.py | |
L = list(range(1000000)) | |
LS = set(L) | |
def findit(): | |
if 500000 in L: | |
pass | |
def findset(): | |
if 500000 in LS: | |
pass | |
import timeit | |
print(timeit.timeit('findit()', 'from __main__ import findit', number=1000)) | |
print(timeit.timeit('findset()', 'from __main__ import findset', number=1000)) | |
brendand@brendand-T450:~$ python algo.py | |
4.09275507927 | |
0.000100135803223 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment