A simple benchmark indicates that the overhead isn't very much (unless the benchmark is completely flawed of course). Consider:
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 += $_; } } }
Prints:
Rate BareFor ExceptFor ForExcept BareFor 1626/s -- -2% -11% ExceptFor 1661/s 2% -- -9% ForExcept 1834/s 13% 10% --
which indicates that the eval overhead is close to the cost of 2 += operations - not a whole lot in other words!
In reply to Re: How expensive is eval { }?
by GrandFather
in thread How expensive is eval { }?
by mscharrer
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |