Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
19 lines (14 sloc) 265 Bytes
require 'benchmark/ips'
ARRAY = (1..100).to_a
def slow
array = []
ARRAY.each { |i| array.push i }
end
def fast
ARRAY.map { |i| i }
end
Benchmark.ips do |x|
x.report('Array#each + push') { slow }
x.report('Array#map') { fast }
x.compare!
end
You can’t perform that action at this time.