Created
November 14, 2012 10:30
-
-
Save gkmngrgn/4071426 to your computer and use it in GitHub Desktop.
dict() vs. {}
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
$ python2.7 -m timeit -n 1000000 -r 5 -v 'd=dict();d["a"]="b"' | |
raw times: 0.182 0.179 0.179 0.18 0.179 | |
1000000 loops, best of 5: 0.179 usec per loop | |
$ python2.7 -m timeit -n 1000000 -r 5 -v 'd={};d["a"]="b"' | |
raw times: 0.0863 0.0859 0.0858 0.0882 0.0877 | |
1000000 loops, best of 5: 0.0858 usec per loop | |
gokmen@rodosto % python3.3 -m timeit -n 1000000 -r 5 -v 'd=dict();d["a"]="b"' | |
raw times: 0.396 0.376 0.359 0.361 0.362 | |
1000000 loops, best of 5: 0.359 usec per loop | |
gokmen@rodosto % python3.3 -m timeit -n 1000000 -r 5 -v 'd={};d["a"]="b"' | |
raw times: 0.196 0.183 0.186 0.189 0.185 | |
1000000 loops, best of 5: 0.183 usec per loop | |
gokmen@rodosto % python2.7 -m timeit -n 1000000 -r 5 -v 'd=dict();d["a"]="b"' | |
raw times: 0.411 0.398 0.396 0.408 0.401 | |
1000000 loops, best of 5: 0.396 usec per loop | |
gokmen@rodosto % python2.7 -m timeit -n 1000000 -r 5 -v 'd={};d["a"]="b"' | |
raw times: 0.146 0.139 0.138 0.14 0.143 | |
1000000 loops, best of 5: 0.138 usec per loop |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment