Skip to content

Instantly share code, notes, and snippets.

@tancnle
Created October 3, 2012 00:32
Show Gist options
  • Save tancnle/3824209 to your computer and use it in GitHub Desktop.
Save tancnle/3824209 to your computer and use it in GitHub Desktop.
Benchmark single and double quotes
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 #{n} 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}
x.report("concat interp") { n.times do; "a #{n} string " + "b #{n} string"; end}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment