Advertisement
Guest User

Untitled

a guest
Nov 5th, 2017
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. #default
  2. Mul: 1.0457470417
  3. Div: 2.65450692177
  4. Sub: 0.871921062469
  5. Divmod: 1.95720386505
  6. Combo: 5.96903395653
  7.  
  8. Mul: 1.01342606544
  9. Div: 2.71628308296
  10. Sub: 0.875638008118
  11. Divmod: 1.95388221741
  12. Combo: 6.09685087204
  13.  
  14. Mul: 1.00868797302
  15. Div: 2.707862854
  16. Sub: 0.874716997147
  17. Divmod: 1.94629001617
  18. Combo: 6.09136390686
  19.  
  20. # math-improvement branch
  21. Mul: 1.01715111732
  22. Div: 2.44827103615
  23. Sub: 0.700042963028
  24. Divmod: 1.807336092
  25. Combo: 5.29910898209
  26.  
  27. Mul: 0.982100009918
  28. Div: 2.4520919323
  29. Sub: 0.691036939621
  30. Divmod: 1.81433415413
  31. Combo: 5.25664901733
  32.  
  33. Mul: 0.98149394989
  34. Div: 2.45189714432
  35. Sub: 0.691314935684
  36. Divmod: 1.8157248497
  37. Combo: 5.25712394714
  38.  
  39.  
  40. bench.py:
  41. from time import time
  42.  
  43. def bench_mul():
  44. for x in range(50000000):
  45. l = long(x)
  46. l *= 2 # mul, power of two
  47. l *= 3 # mul, not power of two
  48.  
  49. def bench_div():
  50. for x in range(50000000):
  51. l = long(x)
  52. l //= 2 # floordiv, power of two
  53. l //= 3 # floordiv, not power of two
  54.  
  55. def bench_sub():
  56. for x in range(50000000):
  57. l = long(x)
  58. l -= 1 # sub
  59.  
  60. def bench_divmod():
  61. for x in range(50000000):
  62. l = long(x)
  63. r, m = divmod(l, 3) # divmod
  64.  
  65. def bench_combo():
  66. for x in range(50000000):
  67. l = long(x)
  68. l *= 2
  69. l //= 2
  70. l *= 3
  71. l //= 3
  72. l -= 1
  73. r, m = divmod(l, 3) # divmod
  74.  
  75. for x in range(3):
  76. t = time()
  77. bench_mul()
  78. print "Mul:", time() - t
  79.  
  80. t = time()
  81. bench_div()
  82. print "Div:", time() - t
  83.  
  84. t = time()
  85. bench_sub()
  86. print "Sub:", time() - t
  87.  
  88. t = time()
  89. bench_divmod()
  90. print "Divmod:", time() - t
  91.  
  92. t = time()
  93. bench_combo()
  94. print "Combo:", time() - t
  95.  
  96. print ""
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement