Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- >>> from timeit import timeit
- >>> timeit("[]")
- 0.040084982867934334
- >>> timeit("list()")
- 0.17704233359267718
- >>> timeit("{}")
- 0.033620194745424214
- >>> timeit("dict()")
- 0.1821558326547077
- >>> timeit("[1,2,3]")
- 0.24316302770330367
- >>> timeit("list((1,2,3))")
- 0.44744206316727286
- >>> timeit("list(foo)", setup="foo=(1,2,3)")
- 0.446036018543964
- >>> timeit("{'a':1, 'b':2, 'c':3}")
- 0.20868602015059423
- >>> timeit("dict(a=1, b=2, c=3)")
- 0.47635635255323905
- >>> timeit("dict(bar)", setup="bar=[('a', 1), ('b', 2), ('c', 3)]")
- 0.9028228448029267
- this_set = {5}
- some_other_set = {}
- In [1]: import dis
- In [2]: a = lambda: {}
- In [3]: b = lambda: dict()
- In [4]: dis.dis(a)
- 1 0 BUILD_MAP 0
- 3 RETURN_VALUE
- In [5]: dis.dis(b)
- 1 0 LOAD_GLOBAL 0 (dict)
- 3 CALL_FUNCTION 0
- 6 RETURN_VALUE
- from datetime import datetime
- then = datetime.now()
- a = dict()
- now = datetime.now()
- print then
- print now
- then = datetime.now()
- b = {}
- now = datetime.now()
- print then
- print now
- mydict = dict(1="foo", 2="bar")
- mydict = {"1":"foo", "2":"bar"}
Add Comment
Please, Sign In to add comment