Skip to content

Instantly share code, notes, and snippets.

@os6sense
Created February 17, 2014 09:54
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 os6sense/9047795 to your computer and use it in GitHub Desktop.
Save os6sense/9047795 to your computer and use it in GitHub Desktop.
require 'benchmark'
Benchmark.bm(20) do |x|
x.report ('<<') do
10_000_000.times do
one = 'one'
two = 'two'
three = 'three'
y = one << two << three
end
end
x.report ('concat') do
10_000_000.times do
one = 'one'
two = 'two'
three = 'three'
y = one.concat(two).concat(three)
end
end
x.report('+') do
10_000_000.times do
one = 'one'
two = 'two'
three = 'three'
y = one + two + three
end
end
x.report('#{one}#{two}#{three}') do
10_000_000.times do
one = 'one'
two = 'two'
three = 'three'
y = "#{one}#{two}#{three}"
end
end
x.report('one#{two}#{three}') do
10_000_000.times do
two = 'two'
three = 'three'
y = "one#{two}#{three}"
end
end
x.report('onetwo#{three}') do
10_000_000.times do
three = 'three'
y = "onetwo#{three}"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment