Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^2: elsif chain vs. dispatch

by ruzam (Curate)
on Apr 27, 2009 at 02:40 UTC ( #760239=note: print w/replies, xml ) Need Help??


in reply to Re: elsif chain vs. dispatch
in thread elsif chain vs. dispatch

$y could be passed as a reference to avoid the string copy further reduce the disadvantage, particularly for large strings.

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?"; } }

On the other hand, maybe the parameter string isn't copied when the function references $_[0] directly?

Replies are listed 'Best First'.
Re^3: elsif chain vs. dispatch
by almut (Canon) on Apr 27, 2009 at 02:53 UTC

    I had tried that.  And had first made the same mistake (and thus got a speed boost of around 800% :) —> the $$_[0] would need to be ${$_[0]}. With that fixed, there's virtually no difference...   In other words, the string isn't copied, even without using references ($_[0] is an alias).

      Interesting. Now I've got some code to review that may stand for another tweak or two :)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://760239]
help
Chatterbox?
LanX has a friend in Berlin who switched to go(lang) and just got a kid ...
[marto]: good morning all
[Corion]: Hi marto ;)
[Discipulus]: Corion ah! you opened a new search path! thanks
[choroba]: LanX No, but they grow and want more!
LanX was conditioned by a female
Discipulus my 'kids' always complain with our car..
[LanX]: true, cars are bad in growing
[marto]: WaitWindow()
[Corion]: Discipulus: You need to respond with 0 to WM_QUERYENDSESSION

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (8)
As of 2017-01-17 09:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you watch meteor showers?




    Results (154 votes). Check out past polls.