Skip to content

Instantly share code, notes, and snippets.

@britishtea
Created October 1, 2013 18:56
Show Gist options
  • Save britishtea/6783304 to your computer and use it in GitHub Desktop.
Save britishtea/6783304 to your computer and use it in GitHub Desktop.
Benchmarking Symbol vs Symbol#to_proc for Enumerable#inject
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