|
|
|
|
|
by matsadler
4433 days ago
|
|
For the cases I have benchmarked concatenation with << has been faster than join on an array. Here's a simple benchmark: require "benchmark"
n = 100_000
Benchmark.bm(4) do |x|
x.report("<<") do
n.times do
"aaaaa " << "bbbbbb " << "ccccc " << "ddddd " << "eeeee " << "fffff"
end
end
x.report("join") do
n.times do
["aaaaa", "bbbbbb", "ccccc", "ddddd", "eeeee", "fffff"].join(" ")
end
end
end
The results I get for this are: user system total real
<< 0.140000 0.000000 0.140000 ( 0.143750)
join 0.230000 0.000000 0.230000 ( 0.228035)
I'd be interested to see if there were any use cases where the relative performance was reversed. |
|