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[0]
end
def slow
ARRAY.first
end
Benchmark.ips do |x|
x.report('Array#[0]') { fast }
x.report('Array#first') { slow }
x.compare!
end
You can’t perform that action at this time.