in reply to Re: Nested evals - are they evil? (sample benchmarks)
in thread Nested evals - are they evil?
Exceptions should be "exceptional". That is, you shouldn't expect them to happen during normal functioning of the program. So lets see what the overhead of providing (unused) exception handling is:
use strict; use warnings; use Benchmark 'cmpthese'; cmpthese(-1, { 'eval' => \&eval_code, 'noeval' => \&no_eval_code, }); sub eval_code { my $x = 0; for (reverse 0..9) { eval { some_more_code ($_); }; if ($@) { error_sub(); } } } sub no_eval_code { for (reverse 0..9) { if ($_==0) { error_sub(); } else { some_more_code ($_); } } } sub some_more_code { } sub error_sub { }
Prints:
Rate eval noeval eval 185563/s -- -7% noeval 198639/s 7% --
In words: the processing cost of an unexercised eval is essentially nothing.
DWIM is Perl's answer to Gödel
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: Nested evals - are they evil? (sample benchmarks)
by cLive ;-) (Prior) on Jul 31, 2007 at 07:05 UTC |
In Section
Seekers of Perl Wisdom