Skip to content

Instantly share code, notes, and snippets.

@larzconwell
Created June 22, 2012 21:27
Show Gist options
  • Save larzconwell/2975301 to your computer and use it in GitHub Desktop.
Save larzconwell/2975301 to your computer and use it in GitHub Desktop.
Desktop% ruby -v (~/Desktop)
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux]
Desktop% cat benchmark_quotes.rb (~/Desktop)
require 'benchmark'
n = 1000000
Benchmark.bm do |x|
x.report('assign single') { n.times do; c = 'a string'; end }
x.report('assign double') { n.times do; c = "a string"; end }
x.report('assign interp') { n.times do; c = "a string #{'b string'}"; end }
x.report('concat single') { n.times do; 'a string ' + 'b string'; end }
x.report('concat double') { n.times do; "a string " + "b string"; end }
end
Desktop% ruby -w benchmark_quotes.rb (~/Desktop)
user system total real
assign single 0.270000 0.010000 0.280000 ( 0.273250)
assign double 0.260000 0.000000 0.260000 ( 0.264455)
assign interp 0.270000 0.000000 0.270000 ( 0.265007)
concat single 0.630000 0.000000 0.630000 ( 0.637348)
concat double 0.630000 0.010000 0.640000 ( 0.634218)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment