Skip to content

Instantly share code, notes, and snippets.

@samflores
Created May 19, 2012 14:09
Show Gist options
  • Save samflores/2730944 to your computer and use it in GitHub Desktop.
Save samflores/2730944 to your computer and use it in GitHub Desktop.
require 'benchmark'
array = (1..10000).to_a
block = proc { |i| i * 2 }
Benchmark.bm(7) do |b|
b.report('map') { array.map &block }
b.report('collect') { array.collect &block }
end
# 1.9.3-p194-perf
# user system total real
# map 0.000000 0.000000 0.000000 ( 0.001042)
# collect 0.000000 0.000000 0.000000 ( 0.000997)
# rbx-2.0.0-dev
# user system total real
# map 0.002415 0.000095 0.002510 ( 0.002400)
# collect 0.002487 0.000029 0.002516 ( 0.002517)
# 1.8.7-p357
# user system total real
# map 0.010000 0.000000 0.010000 ( 0.002115)
# collect 0.000000 0.000000 0.000000 ( 0.002129)
# jruby-1.7.0-dev
# user system total real
# map 0.057000 0.000000 0.057000 ( 0.057000)
# collect 0.028000 0.000000 0.028000 ( 0.028000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment