Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: When should I use a dispatch table?

by chromatic (Archbishop)
on Dec 01, 2006 at 00:02 UTC ( #587085=note: print w/ replies, xml ) Need Help??


in reply to When should I use a dispatch table?

While the code reduction and maintainability is still an advantage, the performance boost may not be all it is cracked up to be.

I summon chromatic's second rule of performance optimization: You're doing IO! That's almost always the slow part!


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:24 UTC
    chromatic,
    In private /msg with madbombX I made this very point. When benchmarking it is important to eliminate as many factors unrelated to what you are testing as possible. In my benchmark generating code however, no IO comes into play (that I can see anyway). This is strictly determining the difference between a series of equality tests (linear search) and a hash lookup, reference dereference, and nearly empty sub execution.

    Cheers - L~R

      In mumble years of programming, I can't think of a single example where the overhead of a dispatch table versus cascading conditionals made a whit of difference compared to the cost of performing IO. Therefore, unless I ever write a FFT or a petabyte-Ethernet driver, I don't see much point to worrying about a handful of milliseconds of difference between two constructs where one is so much more maintainable than the other.

      Then again, almost every program I've ever written performs some sort of IO somewhere.

      As it's the holidays, can I wish that Benchmark refused to give meaningful results for syntax questions and only helped profile various algorithms?

      chromatic already has the IO part handled but your comparison is also getting dwarfed by making those function calls. Remove those too, they're one of the more expensive things you can do in perl (except for IO and just deliberately sleeping).

      ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊

        diotalevi,
        Remove what function calls? The ones that make the dispatch table a dispatch table and subsequently the exact thing I am benchmarking? While I value chromatic's opinion (and your's), there is no IO involved. He was making the point that it is silly to worry about a few microseconds here and there if your program was doing IO.

        So what are you guys trying to say - it is pointless to Benchmark any program that does IO or has function calls? I specifically isolated the bench to the difference between an if/elsif chain and its equivalent dispatch table. I appreciate constructive critism but I am not seeing it here.

        Cheers - L~R

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (7)
As of 2014-10-25 23:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (149 votes), past polls