Skip to content

Instantly share code, notes, and snippets.

@julik
Created March 9, 2009 00:46
Show Gist options
  • Save julik/76027 to your computer and use it in GitHub Desktop.
Save julik/76027 to your computer and use it in GitHub Desktop.
require 'benchmark'
def rc
rand(127).chr
end
ITER = 1_000_000
puts "\n\n rb_format_str"
Benchmark.bm do | x|
x.report do
ITER.times do
str = 'Some %s text %s and more %s text' % [rc, rc, rc]
end
end
end
puts "\n\n unshift"
Benchmark.bm do | x|
x.report do
ITER.times do
str = 'Some ' << rc << ' text ' << rc << ' and more ' << rc << ' text'
end
end
end
puts "\n\n inline"
Benchmark.bm do | x|
x.report do
ITER.times do
str = "Some #{rc} text #{rc} and more #{rc} text"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment