Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'benchmark'
- n = 1_000_000
- Benchmark.bm(20) do |x|
- x.report("chained methods:") do
- n.times do
- ['coconut', 'lemon', 'banana', 'apple'].select { |e| e.size > 5 }
- .map { |e| e.upcase }
- end
- end
- x.report("only reduce:") do
- n.times do
- ['coconut', 'lemon', 'banana', 'apple'].reduce([]) do |acc, e|
- acc << e.upcase if e.size > 5
- acc
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement