Guest User

Untitled

a guest
Jan 18th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. >>> from timeit import timeit
  2. >>> timeit("[]")
  3. 0.040084982867934334
  4. >>> timeit("list()")
  5. 0.17704233359267718
  6. >>> timeit("{}")
  7. 0.033620194745424214
  8. >>> timeit("dict()")
  9. 0.1821558326547077
  10.  
  11. >>> timeit("[1,2,3]")
  12. 0.24316302770330367
  13. >>> timeit("list((1,2,3))")
  14. 0.44744206316727286
  15. >>> timeit("list(foo)", setup="foo=(1,2,3)")
  16. 0.446036018543964
  17. >>> timeit("{'a':1, 'b':2, 'c':3}")
  18. 0.20868602015059423
  19. >>> timeit("dict(a=1, b=2, c=3)")
  20. 0.47635635255323905
  21. >>> timeit("dict(bar)", setup="bar=[('a', 1), ('b', 2), ('c', 3)]")
  22. 0.9028228448029267
  23.  
  24. this_set = {5}
  25. some_other_set = {}
  26.  
  27. In [1]: import dis
  28. In [2]: a = lambda: {}
  29. In [3]: b = lambda: dict()
  30.  
  31. In [4]: dis.dis(a)
  32. 1 0 BUILD_MAP 0
  33. 3 RETURN_VALUE
  34.  
  35. In [5]: dis.dis(b)
  36. 1 0 LOAD_GLOBAL 0 (dict)
  37. 3 CALL_FUNCTION 0
  38. 6 RETURN_VALUE
  39.  
  40. from datetime import datetime
  41. then = datetime.now()
  42. a = dict()
  43. now = datetime.now()
  44. print then
  45. print now
  46.  
  47. then = datetime.now()
  48. b = {}
  49. now = datetime.now()
  50. print then
  51. print now
  52.  
  53. mydict = dict(1="foo", 2="bar")
  54.  
  55. mydict = {"1":"foo", "2":"bar"}
Add Comment
Please, Sign In to add comment