Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'benchmark'
- require 'active_support/all'
- arr = Array.new(1000_0000) { rand(1...20) }
- Benchmark.bm do |benchmark|
- benchmark.report "arr.sum { |n| n.odd? ? n : 0 }" do
- arr.sum { |n| n.odd? ? n : 0 }
- end
- benchmark.report "arr.select(&:odd?).sum" do
- arr.select(&:odd?).sum
- end
- benchmark.report "arr.select(&:odd?).sum" do
- arr.select{|a| a.odd?}.sum
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement