Created
December 3, 2009 12:17
-
-
Save raggi/248110 to your computer and use it in GitHub Desktop.
closures aren't cheap, srsly
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" | |
arr = [1,2,3,4,5,6,7,8,9,0] * 100 | |
GC.start | |
TESTS = 10_000 | |
Benchmark.bmbm do |results| | |
results.report("map:") { TESTS.times { arr.map { |i| i } } } | |
results.report("inj:") { TESTS.times { a = []; arr.inject(a, :<<) } } | |
end | |
# Rehearsal ---------------------------------------- | |
# map: 1.790000 0.020000 1.810000 ( 2.070154) | |
# inj: 1.700000 0.010000 1.710000 ( 1.854312) | |
# ------------------------------- total: 3.520000sec | |
# | |
# user system total real | |
# map: 1.780000 0.010000 1.790000 ( 1.839637) | |
# inj: 1.700000 0.010000 1.710000 ( 1.752435) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment