Skip to content

Instantly share code, notes, and snippets.

@abhilashak
Forked from alno/bench_str_building.rb
Created June 12, 2021 15:10
Show Gist options
  • Save abhilashak/6ed5b9d72be8eb9f01bf59e47aecef6f to your computer and use it in GitHub Desktop.
Save abhilashak/6ed5b9d72be8eb9f01bf59e47aecef6f to your computer and use it in GitHub Desktop.
Benchmark: interpolation vs concatenation in Ruby
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}" } }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment