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

Users who have contributed to this file

18 lines (13 sloc) 268 Bytes
require 'benchmark/ips'
ARRAY = [*1..100]
def fast
ARRAY.min_by { |x| x.succ }
end
def slow
ARRAY.sort_by { |x| x.succ }.first
end
Benchmark.ips do |x|
x.report('Enumerable#min_by') { fast }
x.report('Enumerable#sort_by...first') { slow }
x.compare!
end
You can’t perform that action at this time.