Skip to content

Instantly share code, notes, and snippets.

@taotetek
Created October 21, 2010 01:08
Show Gist options
  • Save taotetek/637717 to your computer and use it in GitHub Desktop.
Save taotetek/637717 to your computer and use it in GitHub Desktop.
require 'benchmark'
a = "this"
b = "is"
c = "a"
d = "benchmark"
n = 100000000
Benchmark.bmbm do |x|
x.report("plus:") {
1.upto(n) do |i|
string = a + "::" + b + "::" + c + "::" + d
end
}
x.report("interpolate:") {
1.upto(n) do |i|
string = "#{a}::#{b}::#{c}::#{d}"
end
}
x.report("array:") {
1.upto(n) do |i|
string = [a,b,c,d].join("::")
end
}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment