http://qs321.pair.com?node_id=587084


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?

Replies are listed 'Best First'.
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