Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
2 contributors

Users who have contributed to this file

@JuanitoFatas @DamirSvrtan
18 lines (13 sloc) 297 Bytes
require 'benchmark/ips'
ARRAY = [*1..100]
def fast
ARRAY.reverse.detect { |x| (x % 10).zero? }
end
def slow
ARRAY.select { |x| (x % 10).zero? }.last
end
Benchmark.ips do |x|
x.report('Enumerable#reverse.detect') { fast }
x.report('Enumerable#select.last') { slow }
x.compare!
end
You can’t perform that action at this time.