Skip to content

Instantly share code, notes, and snippets.

@filipebarcos
Created April 10, 2014 00:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save filipebarcos/10333416 to your computer and use it in GitHub Desktop.
Save filipebarcos/10333416 to your computer and use it in GitHub Desktop.
require 'benchmark'
n = 1000000
Benchmark.bm(15) 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("concat single") { n.times do; 'a string ' + 'b string'; end}
x.report("concat double") { n.times do; "a string " + "b string"; end}
end
# $ ruby -v
# ruby 2.0.0p353 (2013-11-22 revision 43784) [x86_64-darwin13.0.0]
# $ ruby string.rb
# user system total real
# assign single 0.140000 0.000000 0.140000 ( 0.136359)
# assign double 0.130000 0.010000 0.140000 ( 0.134131)
# concat single 0.330000 0.000000 0.330000 ( 0.331155)
# concat double 0.340000 0.000000 0.340000 ( 0.339431)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment