Advertisement
Guest User

Untitled

a guest
Feb 8th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.26 KB | None | 0 0
  1. puts "Ruby #{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}:\n"
  2.  
  3. require 'benchmark/ips'
  4.  
  5. def without_block(x,y,z); end
  6. def with_block(x,y,z,&b); end
  7.  
  8. puts
  9. puts '* no passing a block'
  10. puts
  11.  
  12. Benchmark.ips do |x|
  13. x.report 'method with block' do
  14. with_block(1,2,3)
  15. end
  16.  
  17. x.report 'method without block' do
  18. without_block(1,2,3)
  19. end
  20.  
  21. x.compare!
  22. end
  23.  
  24. puts
  25. puts '* passing a block'
  26. puts
  27.  
  28. Benchmark.ips do |x|
  29. x.report 'method with block' do
  30. with_block(1,2,3) { }
  31. end
  32.  
  33. x.report 'method without block' do
  34. without_block(1,2,3) { }
  35. end
  36.  
  37. x.compare!
  38. end
  39.  
  40. # Ruby 2.3.0-p0:
  41. #
  42. # * no passing a block
  43. #
  44. # Calculating -------------------------------------
  45. # method with block 100.240k i/100ms
  46. # method without block 103.667k i/100ms
  47. # -------------------------------------------------
  48. # method with block 5.498M (± 0.4%) i/s - 27.566M
  49. # method without block 6.616M (± 0.8%) i/s - 33.070M
  50. #
  51. # Comparison:
  52. # method without block: 6615605.0 i/s
  53. # method with block: 5497671.8 i/s - 1.20x slower
  54. #
  55. #
  56. # * passing a block
  57. #
  58. # Calculating -------------------------------------
  59. # method with block 73.786k i/100ms
  60. # method without block 104.354k i/100ms
  61. # -------------------------------------------------
  62. # method with block 1.779M (± 6.0%) i/s - 8.854M
  63. # method without block 6.419M (± 2.6%) i/s - 32.141M
  64. #
  65. # Comparison:
  66. # method without block: 6418544.7 i/s
  67. # method with block: 1779275.9 i/s - 3.61x slower
  68. #
  69. #
  70. #
  71. # Ruby 2.2.4-p230:
  72. #
  73. # * no passing a block
  74. #
  75. # Calculating -------------------------------------
  76. # method with block 96.338k i/100ms
  77. # method without block 98.046k i/100ms
  78. # -------------------------------------------------
  79. # method with block 4.099M (± 2.3%) i/s - 20.520M
  80. # method without block 5.280M (± 0.5%) i/s - 26.472M
  81. #
  82. # Comparison:
  83. # method without block: 5279791.5 i/s
  84. # method with block: 4098867.6 i/s - 1.29x slower
  85. #
  86. #
  87. # * passing a block
  88. #
  89. # Calculating -------------------------------------
  90. # method with block 71.199k i/100ms
  91. # method without block 101.587k i/100ms
  92. # -------------------------------------------------
  93. # method with block 1.712M (± 2.7%) i/s - 8.615M
  94. # method without block 5.691M (± 0.4%) i/s - 28.546M
  95. #
  96. # Comparison:
  97. # method without block: 5691093.6 i/s
  98. # method with block: 1711522.5 i/s - 3.33x slower
  99. #
  100. #
  101. #
  102. # Ruby 2.1.8-p440:
  103. #
  104. # * no passing a block
  105. #
  106. # Calculating -------------------------------------
  107. # method with block 101.878k i/100ms
  108. # method without block 103.593k i/100ms
  109. # -------------------------------------------------
  110. # method with block 5.184M (± 1.5%) i/s - 25.979M
  111. # method without block 5.757M (± 0.8%) i/s - 28.799M
  112. #
  113. # Comparison:
  114. # method without block: 5757382.9 i/s
  115. # method with block: 5183517.3 i/s - 1.11x slower
  116. #
  117. #
  118. # * passing a block
  119. #
  120. # Calculating -------------------------------------
  121. # method with block 63.973k i/100ms
  122. # method without block 107.936k i/100ms
  123. # -------------------------------------------------
  124. # method with block 1.253M (± 3.5%) i/s - 6.269M
  125. # method without block 5.512M (± 0.7%) i/s - 27.632M
  126. #
  127. # Comparison:
  128. # method without block: 5511681.9 i/s
  129. # method with block: 1253081.9 i/s - 4.40x slower
  130. #
  131. #
  132. #
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement