Skip to content

Instantly share code, notes, and snippets.

@mwpastore
Created November 3, 2015 06:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mwpastore/a206aab38a4070452563 to your computer and use it in GitHub Desktop.
Save mwpastore/a206aab38a4070452563 to your computer and use it in GitHub Desktop.
Bechmark inject with symbol vs. & (to_proc)
require 'fruity'
ints = (0..9_999_999).to_a
compare do
block { ints.reduce(0, &:+) }
symbol { ints.reduce(0, :+) }
end
# $ rbenv version
# 2.2.3 (set by RBENV_VERSION environment variable)
# $ ruby benchmark_inject.rb
# Running each test once. Test will take about 28 seconds.
# symbol is faster than block by 30.000000000000004% ± 1.0%
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment