Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
25 lines (18 sloc) 339 Bytes
require "rubygems"
require "benchmark/ips"
ARRAY = (1..1000).to_a
def fastest
ARRAY.inject(:+)
end
def fast
ARRAY.inject(&:+)
end
def slow
ARRAY.inject { |a, i| a + i }
end
Benchmark.ips do |x|
x.report('inject symbol') { fastest }
x.report('inject to_proc') { fast }
x.report('inject block') { slow }
x.compare!
end
You can’t perform that action at this time.