Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
18 lines (13 sloc) 203 Bytes
require 'benchmark/ips'
ARRAY = [*1..100]
def fast
ARRAY[-1]
end
def slow
ARRAY.last
end
Benchmark.ips do |x|
x.report('Array#[-1]') { fast }
x.report('Array#last') { slow }
x.compare!
end
You can’t perform that action at this time.