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

Users who have contributed to this file

22 lines (17 sloc) 260 Bytes
require 'benchmark/ips'
ARRAY = [*1..100]
def slow
for number in ARRAY do
number
end
end
def fast
ARRAY.each do |number|
number
end
end
Benchmark.ips do |x|
x.report('For loop') { slow }
x.report('#each') { fast }
x.compare!
end
You can’t perform that action at this time.