Skip to content

Instantly share code, notes, and snippets.

@jbrown
Created November 20, 2011 21:03
Show Gist options
  • Save jbrown/1380909 to your computer and use it in GitHub Desktop.
Save jbrown/1380909 to your computer and use it in GitHub Desktop.
Benchmarking ruby single/double quotes
require 'benchmark'
puts "\npatchlevel: #{RUBY_PATCHLEVEL}, release_date: #{RUBY_RELEASE_DATE}, ruby_version: #{RUBY_VERSION}, ruby_platform: #{RUBY_PLATFORM}\n"
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