Benchmark.bm(10) do |x|
x.report("With '+=' :") {string = ""; n.times {|n| string += "e"} }
x.report("With '<<' :") {string = ""; n.times {|n|string << "e"} }
x.report("With #concat :") {string = ""; n.times {|n|string.concat("e")} }
end
end
Results with n = 5000:
user system total real
With '+=' : 0.010000 0.010000 0.020000 ( 0.022831)
With '<<' : 0.000000 0.000000 0.000000 ( 0.001734)
With concat : 0.000000 0.000000 0.000000 (0.001689)
Results with n = 50000:
user system total real
With '+=' : 0.710000 0.000000 0.710000 ( 0.737932)
With '<<' : 0.020000 0.000000 0.020000 ( 0.019771)
With concat : 0.020000 0.000000 0.020000 ( 0.019853)
Aucun commentaire:
Enregistrer un commentaire