Skip to content

Instantly share code, notes, and snippets.

@mmr
Created December 30, 2014 14:10
Show Gist options
  • Save mmr/456d1cc3f6943476ed3a to your computer and use it in GitHub Desktop.
Save mmr/456d1cc3f6943476ed3a to your computer and use it in GitHub Desktop.
{} vs dict
In [1]: from timeit import timeit
In [2]: a = lambda: dict()
In [3]: b = lambda: {}
In [4]: n = 1000000
In [5]: [(timeit(a, number=n), timeit(b, number=n)) for x in range(10)]
Out[5]:
[(0.18719196319580078, 0.0938410758972168),
(0.16950392723083496, 0.09456491470336914),
(0.1706409454345703, 0.09294795989990234),
(0.16990113258361816, 0.09202790260314941),
(0.16895294189453125, 0.09336018562316895),
(0.1697380542755127, 0.09495186805725098),
(0.1697099208831787, 0.09295296669006348),
(0.16980290412902832, 0.09306979179382324),
(0.1685340404510498, 0.09412407875061035),
(0.17179489135742188, 0.09311914443969727)]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment