Skip to content

Instantly share code, notes, and snippets.

@drewbaumann
Forked from alno/bench_str_building.rb
Last active August 29, 2015 14:14
Show Gist options
  • Save drewbaumann/7faf97ee267f359d1f9c to your computer and use it in GitHub Desktop.
Save drewbaumann/7faf97ee267f359d1f9c to your computer and use it in GitHub Desktop.
require 'benchmark'
count = 1000000
Benchmark.benchmark do |bm|
bm.report("concat") { count.times { 11.to_s + '/' + 12.to_s } }
bm.report("interp") { count.times { "#{11}/#{12}" } }
bm.report("join") { count.times { ["11", "12"].join("") } }
end
@drewbaumann
Copy link
Author

concat 0.400000 0.000000 0.400000 ( 0.405742)
interp 0.390000 0.000000 0.390000 ( 0.390511)
join 0.660000 0.010000 0.670000 ( 0.660068)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment