Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'benchmark'
- N = 1000
- BASIC_LENGTH = 10
- puts RUBY_DESCRIPTION
- 5.times do |factor|
- length = BASIC_LENGTH * (10 ** factor)
- puts "_" * 60 + "\nLENGTH: #{length}"
- Benchmark.bm(10, '+= VS <<', '#{} VS <<') do |x|
- concat_report = x.report("+=") do
- str1 = ""
- str2 = "s" * length
- N.times { str1 += str2 }
- end
- modify_report = x.report("<<") do
- str1 = "s"
- str2 = "s" * length
- N.times { str1 << str2 }
- end
- interpolate_report = x.report('#{}') do
- str1 = "s"
- str2 = "s" * length
- N.times { str1 = "#{str1}#{str2}" }
- end
- [concat_report / modify_report, interpolate_report / modify_report]
- end
- end
Add Comment
Please, Sign In to add comment