Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save deepthawtz/997398 to your computer and use it in GitHub Desktop.

Select an option

Save deepthawtz/997398 to your computer and use it in GitHub Desktop.
Symbol.to_proc vs. regular block with arguments
require "benchmark"
n = 1_000_000
Benchmark.bm do |x|
x.report("symbol to proc ") { Array.new(n, "45").map(&:to_i) }
x.report("regular block with args") { Array.new(n, "45").map {|i| i.to_i} }
end
__END__
Using /Users/deepthawtz/.rvm/gems/ree-1.8.7-2011.03
user system total real
symbol to proc 2.500000 0.010000 2.510000 ( 2.517850)
regular block with args 0.330000 0.000000 0.330000 ( 0.333694)
Using /Users/deepthawtz/.rvm/gems/ruby-1.9.2-p180
user system total real
symbol to proc 0.170000 0.010000 0.180000 ( 0.172500)
regular block with args 0.210000 0.000000 0.210000 ( 0.220909)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment