Skip to content

Instantly share code, notes, and snippets.

@tal
Created January 13, 2011 20:29
Show Gist options
  • Select an option

  • Save tal/778534 to your computer and use it in GitHub Desktop.

Select an option

Save tal/778534 to your computer and use it in GitHub Desktop.
require 'benchmark'
arr = [*0..99999]
num = 100
Benchmark.bmbm do |x|
x.report("sym#to_proc") do
num.times do
arr.each(&:to_i)
end
end
x.report("traditional block") do
num.times do
arr.each {|i| i.to_i}
end
end
end
# For: arr = [*0..99999] and num = 100
# Rehearsal -----------------------------------------------------
# sym#to_proc 3.130000 0.010000 3.140000 ( 3.137098)
# traditional block 1.470000 0.000000 1.470000 ( 1.477588)
# -------------------------------------------- total: 4.610000sec
#
# user system total real
# sym#to_proc 3.060000 0.010000 3.070000 ( 3.069627)
# traditional block 1.470000 0.000000 1.470000 ( 1.475297)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment