Skip to content

Instantly share code, notes, and snippets.

@mdespuits
Forked from alno/bench_str_building.rb
Created August 31, 2012 15:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mdespuits/3554662 to your computer and use it in GitHub Desktop.
Save mdespuits/3554662 to your computer and use it in GitHub Desktop.
Benchmark: interpolation vs concatenation in Ruby
require 'benchmark'
count = 1_000_000
Benchmark.benchmark do |bm|
bm.report("concat") { count.times { 11.to_s + '/' + 12.to_s } }
bm.report("interp") { count.times { "#{11}/#{12}" } }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment