Guest User

Untitled

a guest
Mar 23rd, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. require 'benchmark'
  2.  
  3. N = 1000
  4. BASIC_LENGTH = 10
  5.  
  6. puts RUBY_DESCRIPTION
  7.  
  8. 5.times do |factor|
  9. length = BASIC_LENGTH * (10 ** factor)
  10. puts "_" * 60 + "\nLENGTH: #{length}"
  11.  
  12. Benchmark.bm(10, '+= VS <<', '#{} VS <<') do |x|
  13. concat_report = x.report("+=") do
  14. str1 = ""
  15. str2 = "s" * length
  16. N.times { str1 += str2 }
  17. end
  18.  
  19. modify_report = x.report("<<") do
  20. str1 = "s"
  21. str2 = "s" * length
  22. N.times { str1 << str2 }
  23. end
  24.  
  25. interpolate_report = x.report('#{}') do
  26. str1 = "s"
  27. str2 = "s" * length
  28. N.times { str1 = "#{str1}#{str2}" }
  29. end
  30.  
  31. [concat_report / modify_report, interpolate_report / modify_report]
  32. end
  33. end
Add Comment
Please, Sign In to add comment