Skip to content

Instantly share code, notes, and snippets.

@ramblex
Last active December 17, 2015 02:09
Show Gist options
  • Save ramblex/5533825 to your computer and use it in GitHub Desktop.
Save ramblex/5533825 to your computer and use it in GitHub Desktop.
require 'benchmark'
n = 1000000
b = "b string".freeze
Benchmark.bmbm do |x|
x.report("use interpola") { n.times do; a = 'a string'; "#{a} #{b}"; end}
x.report("concat single") { n.times do; a = 'a string'; a + b; end}
x.report("use << single") { n.times do; a = 'a string'; a << b; end}
end
Rehearsal -------------------------------------------------
use interpola 0.590000 0.000000 0.590000 ( 0.591011)
concat single 0.280000 0.000000 0.280000 ( 0.286938)
use << single 0.270000 0.000000 0.270000 ( 0.261599)
---------------------------------------- total: 1.140000sec
user system total real
use interpola 0.580000 0.000000 0.580000 ( 0.585043)
concat single 0.300000 0.000000 0.300000 ( 0.294077)
use << single 0.250000 0.000000 0.250000 ( 0.252018)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment