Skip to content

Instantly share code, notes, and snippets.

@mikecmpbll
Created June 22, 2015 20:01
Show Gist options
  • Save mikecmpbll/eb63d1f33a25a153edae to your computer and use it in GitHub Desktop.
Save mikecmpbll/eb63d1f33a25a153edae to your computer and use it in GitHub Desktop.
a = [1,2]
Benchmark.ips do |x|
x.report("reduce") { a.reduce(:*) }
x.report("other") { a[0] * a[1] }
x.compare!
end
Calculating -------------------------------------
reduce 56.411k i/100ms
other 78.330k i/100ms
-------------------------------------------------
reduce 1.644M (± 8.7%) i/s - 8.180M
other 4.696M (±14.1%) i/s - 22.951M
Comparison:
other: 4696074.3 i/s
reduce: 1643904.7 i/s - 2.86x slower
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment