Last active
December 12, 2015 06:48
-
-
Save nolan/4731578 to your computer and use it in GitHub Desktop.
Benchmark flatten vs manual array creation
This file contains 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 "benchmark" | |
n = 50000 | |
a = ('A'..'Z').to_a | |
a = a.zip(a) # [["A", "A"], ["B", "B"], ["C", "C"]...] | |
Benchmark.bm(7) do |x| | |
x.report("manual:") { n.times do; a.map {|b| ['X', b[0], b[1]] }; end } | |
x.report("flatten:") { n.times do; a.map {|b| ['X', b].flatten }; end } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Under: ruby 1.9.3p327 (2012-11-10) [x86_64-darwin12.2.0]