Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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)
Add Comment
Please, Sign In to add comment