Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: When should I use a dispatch table?

by GrandFather (Cardinal)
on Nov 30, 2006 at 23:55 UTC ( #587084=note: print w/ replies, xml ) Need Help??


in reply to When should I use a dispatch table?

I must admit that my eyes popped somewhat at "I have re-written your code to be much more efficient." in that node. However I was too busy to bother benchmarking it and the dispatch table is much cleaner than the original code in any case so I let it go.

I'm glad to see that you've followed up with some actual testing and the result doesn't much surprise me. Another thing to consider is that if at the time of coding you know the likely hit rate for each of the tests, the chained if/elsif can be much more efficient by testing the most likely hits first. That is still nasty code to write, test and maintain compared with the dispatch table, but stooping to "assembly language" techniques has to be a win sometimes. :)


DWIM is Perl's answer to Gödel


Comment on Re: When should I use a dispatch table?
Re^2: When should I use a dispatch table?
by Limbic~Region (Chancellor) on Dec 01, 2006 at 00:20 UTC
    GrandFather,
    I am not sure if you looked at the options of this benchmark generating code but I included the ability for testing likely hit rates.

    Cheers - L~R

      I admit to my shame that I didn't do more than glance at your code and missed that (let's blame pressure of work). However I really intended to suggest that an implementor of such code ought consider the effect of such an optimisation, rather than that you would be remiss in not accounting for it in your benchmark. Kudos for allowing for hit rate optimisation though!


      DWIM is Perl's answer to Gödel

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://587084]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2014-09-17 01:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (55 votes), past polls