Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re: elsif chain vs. dispatch

by Burak (Chaplain)
on Apr 26, 2009 at 22:19 UTC ( #760205=note: print w/replies, xml ) Need Help??

in reply to elsif chain vs. dispatch

Your example is not practical. Dispatch tables are usually defined once outside the code that runs it. I suggest creating a test code like:
my %dispatch; sub elsifchain { ... } sub dispatch { ... }

Replies are listed 'Best First'.
Re^2: elsif chain vs. dispatch
by moritz (Cardinal) on Apr 26, 2009 at 22:28 UTC
    That's a good point - the dispatch table is created on every invocation, the elsif code variant is only compiled once. The second point is that the split calls actually obscure the test results, not clarify them.

    So what I did was to change all the alternatives to return a literal 'A' instead, and to build the dispatch table only once. That's the result:

    Rate elsif dispatch elsif 252062/s -- -73% dispatch 927942/s 268% --
      I knew I was doing something dumb. Thanks!