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

Re: elsif chain vs. dispatch

by almut (Canon)
on Apr 26, 2009 at 22:23 UTC ( #760206=note: print w/replies, xml ) Need Help??

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

    $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?

      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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://760206]
[Corion]: choroba: I'm still using spod5 as my pod-to-ooxml- converter didn't really get off the ground so far
[choroba]: Slidy is basically HTML, so I'm not sure I really fly high :)
choroba should make his presentation scaffolding public
[Corion]: choroba: spod5 converts pod to S5 HTML, so it's also still basic. I find the lack of animations (in the sense of "highlight this", "highlight that" in code) somewhat tedious as I do it with rendered PNGs
[Corion]: I haven't found a good way to include/use the source SVGs I use for creating the PNGs directly as animations
[ambrus]: Presentations come in many different shapes, and so slides do as well.
[Corion]: Doing that in Powerpoint or Ooxml would be nice(r) but I'm much quicker doing the outline of a presentation and the code as Pod

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (13)
As of 2017-09-26 10:01 GMT
Find Nodes?
    Voting Booth?
    During the recent solar eclipse, I:

    Results (293 votes). Check out past polls.