Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Re: When should I use a dispatch table?

by GrandFather (Sage)
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?

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

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2016-10-25 02:31 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (313 votes). Check out past polls.