On a lark, I did this, and was shocked at the result. Why the massive difference in performance between "begin; end" within a block, and "{ }" within a block?
I may do some more tinkering with this later on.
require 'benchmark'
N = 10_000_000
Benchmark.bmbm do |b|
b.report 'begin' do
N.times { begin; rescue; end }
end
b.report 'begin no rescue' do
N.times { begin; end }
end
b.report 'no begin nested' do
N.times { { } }
end
b.report 'plain' do
N.times { }
end
end
Rehearsal ---------------------------------------------------
begin 3.547000 0.000000 3.547000 ( 3.656000)
begin no rescue 2.797000 0.000000 2.797000 ( 2.860000)
no begin nested 38.062000 0.453000 38.515000 ( 40.593000)
plain 1.735000 0.000000 1.735000 ( 1.782000)
----------------------------------------- total: 46.594000sec
user system total real
begin 3.516000 0.000000 3.516000 ( 3.594000)
begin no rescue 2.750000 0.000000 2.750000 ( 2.828000)
no begin nested 36.422000 0.297000 36.719000 ( 38.797000)
plain 1.750000 0.000000 1.750000 ( 1.781000)