Created
October 9, 2018 07:08
-
-
Save computercolin/363a44e1268c93ef6190169ac4d99835 to your computer and use it in GitHub Desktop.
Py 3.6 Benchmark Dict v. List ... even small dicts, faster
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
# dict | |
1000000 loops, best of 3: 1.16 usec per loop | |
# list | |
1000000 loops, best of 3: 1.56 usec per loop | |
# tuple | |
1000000 loops, best of 3: 1.51 usec per loop | |
# set | |
1000000 loops, best of 3: 1.16 usec per loop |
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
python -m timeit -s "l={k:k for k in range(15)}" "[i for i in range(8) if i in l]" | |
python -m timeit -s "l=[k for k in range(15)]" "[i for i in range(8) if i in l]" | |
python -m timeit -s "l=tuple([k for k in range(15)])" "[i for i in range(8) if i in l]" | |
python -m timeit -s "l=set([k for k in range(15)])" "[i for i in range(8) if i in l]" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment