in reply to elsif chain vs. dispatch
If you don't recreate the dispatch table upon every invocation of dispatch() by placing it outside of the routine, the difference already is much smaller:
Rate dispatch elsif dispatch 9363/s -- -12% elsif 10627/s 13% --
even though in that case, there's still a disadvantage on the side of the dispatch table, because the $y needs to be passed to the anonymous sub...
my %dispatch=( A=>sub { split(/!/,$_[0]); }, ... ); sub dispatch { my $x=$letters[random($nLetters)]; my $y='xyzzy!' x random(1000); if (exists $dispatch{$x}) { $dispatch{$x}->($y); } else { warn "Huh?"; } }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: elsif chain vs. dispatch
by ruzam (Curate) on Apr 27, 2009 at 02:40 UTC | |
by almut (Canon) on Apr 27, 2009 at 02:53 UTC | |
by ruzam (Curate) on Apr 27, 2009 at 03:39 UTC |
In Section
Seekers of Perl Wisdom