use strict; use warnings; use Benchmark qw(cmpthese); cmpthese ( -1, { BareFor => \&dofor, ExceptFor => \&doefor, ForExcept => \&dofore, } ); sub dofor { my $sum = 0; for (1 .. 1000) { $sum += $_; $sum += $_; $sum += $_; } } sub dofore { my $sum = 0; for (1 .. 1000) { eval {$sum += $_;} } } sub doefor { my $sum = 0; eval { for (1 .. 1000) { $sum += $_; $sum += $_; $sum += $_; } } } #### Rate BareFor ExceptFor ForExcept BareFor 1626/s -- -2% -11% ExceptFor 1661/s 2% -- -9% ForExcept 1834/s 13% 10% --