Created
October 1, 2013 18:56
-
-
Save britishtea/6783304 to your computer and use it in GitHub Desktop.
Benchmarking Symbol vs Symbol#to_proc for Enumerable#inject
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" | |
require "benchmark/ips" | |
array = Range.new(1,1_000_000).to_a | |
Benchmark.bmbm do |x| | |
x.report("#inject &:*") { array.inject &:* } | |
x.report("#inject :*") { array.inject :* } | |
end | |
# Rehearsal ----------------------------------------------- | |
# #inject &:+ 0.150000 0.000000 0.150000 ( 0.170740) | |
# #inject :+ 0.110000 0.000000 0.110000 ( 0.118186) | |
# -------------------------------------- total: 0.260000sec | |
# user system total real | |
# #inject &:+ 0.140000 0.000000 0.140000 ( 0.172540) | |
# #inject :+ 0.100000 0.000000 0.100000 ( 0.114036) | |
# [Finished in 5.2s] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment