Created
February 13, 2013 19:08
-
-
Save gabetax/4947200 to your computer and use it in GitHub Desktop.
ruby String#+ vs interpolation benchmark
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'faker' | |
require 'benchmark' | |
times = 10000000 | |
str = 'hello world' | |
Benchmark.bm do |b| | |
b.report("+ with space") do | |
times.times do | |
str + str | |
end | |
end | |
b.report("+ without space") do | |
times.times do | |
str + ' ' + str | |
end | |
end | |
b.report("interpolation") do | |
times.times do | |
"#{str}#{str}" | |
end | |
end | |
end |
Author
gabetax
commented
Feb 13, 2013
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment