Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

RE: RE (tilly) 1: Expand your world

by jlp (Friar)
on Aug 20, 2000 at 11:13 UTC ( #28710=note: print w/replies, xml ) Need Help??

in reply to RE (tilly) 1: Expand your world
in thread Expand your world

I have trouble with your assertion that this will be more efficient. Any gain in perfomance by using a hash instead of an if-else clause is going to be offset by the multiple eval()s. I also contend that it is just as easy to add another elsif as to add another key-value pair to the hash. Anyway, that's just my opinion.

Replies are listed 'Best First'.
R (tilly) 3: Expand your world
by tilly (Archbishop) on Aug 20, 2000 at 11:30 UTC
    If you have a long list of arguments, it will be.

    First of all evals don't cost much more than just having had that much code in the first place. Secondly all of the evals take place up front. So it is just like having a longer program.

    But at runtime I have a hash lookup (constant time no matter how large the hash is) rather than repeated tests, So I have traded compile time away for faster run-time behaviour.

    FWIW I first realized the importance of this win when trying to speed up a program that categorized states into ACLI regions for a huge amount of text information. Just moving the logic out of if/elsif/elsif/else type constructs into hash lookups and/or smart REs was an order of magnitude improvement.

    Cheers, Ben

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (2)
As of 2023-06-11 01:04 GMT
Find Nodes?
    Voting Booth?
    How often do you go to conferences?

    Results (40 votes). Check out past polls.