Skip to content

Instantly share code, notes, and snippets.

@fidelisrafael
Last active December 24, 2015 22:39
Show Gist options
  • Save fidelisrafael/6874640 to your computer and use it in GitHub Desktop.
Save fidelisrafael/6874640 to your computer and use it in GitHub Desktop.
Simple benchmark (simple test from Rodrigo Alves : https://gist.github.com/rodrigoalvesvieira/6255267)
require 'benchmark'
Benchmark.bm(10) do |x|
x.report("Array#join") {
10000.times do
["'", ("a".."z").to_a.join("' , '"), "'"].join
end
}
x.report("String#<<") {
10000.times do
res = ""
("a".."z").to_a.each do |l|
res << "'#{l}'" << ", "
end
end
}
end
@fidelisrafael
Copy link
Author

                 user     system      total        real
Array#join   0.100000   0.000000   0.100000 (  0.107406)
String#<<    0.230000   0.000000   0.230000 (  0.229317)

--------------------
testing with 50_000 loops

                 user     system      total        real
Array#join   0.520000   0.000000   0.520000 (  0.517532)
String#<<    1.140000   0.000000   1.140000 (  1.149118)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment