Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
1 contributor

Users who have contributed to this file

17 lines (13 sloc) 275 Bytes
require 'benchmark/ips'
ARRAY = [*1..100]
def slow
ARRAY.select { |x| x.eql?(15) }.first
end
def fast
ARRAY.detect { |x| x.eql?(15) }
end
Benchmark.ips(20) do |x|
x.report('Enumerable#select.first') { slow }
x.report('Enumerable#detect') { fast }
x.compare!
end
You can’t perform that action at this time.