Created
April 3, 2013 20:44
Revisions
-
Matt Bridges created this gist
Apr 3, 2013 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,34 @@ require 'benchmark' ITERATIONS = 10_000 Benchmark.bm do |bm| bm.report("#<< -> #flatten!: ") do array = [1,2,3] ITERATIONS.times do array << [4,5,6] array.flatten! end end bm.report("+=: ") do array = [1,2,3] ITERATIONS.times do array += [4,5,6] end end bm.report("#concat: ") do array = [1,2,3] ITERATIONS.times do array.concat [4,5,6] end end end # OUTCOME # # => user system total real # => #<< -> #flatten!: 8.280000 0.200000 8.480000 ( 8.473539) # => +=: 0.240000 0.350000 0.590000 ( 0.599704) # => #concat: 0.000000 0.000000 0.000000 ( 0.001990)