Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Efficiency of multiple if statements (code)

by deprecated (Priest)
on May 09, 2001 at 01:18 UTC ( #78963=note: print w/replies, xml ) Need Help??


in reply to Efficiency of multiple if statements

I am surprised nobody has mentioned this yet, but just a few days ago I was given the same decision. A big hunka hunka burning regex or a series of nested conditionals. The result is at Optimization for readability and speed (code).

The bottom line: The regex was 10 times faster than the if statements. Running it once, it wouldnt have made a difference. Running it 200 times, it did make a difference. And merlyn was right. Looking back on it, it really seems silly to have done that from a perl programmer point of view.

Something else you may be interested in (and one of the ways I did simplify and readbilityize the code) is here, at Using arrays of qr!! to simplify larger RE's for readability (code).. You might find that using a sequence of qr!!'s in your code may not only increase its readbility but also its speed.

Looking back at it, I think I wound up updating everyone in the CB with regards to speed. I did benchmark everything and it turned out to be 10x faster. The reason that particular node didnt report any speed increase is I was doing something rather stupid elsewhere in the program. :)

brother dep.

psssst, you probably could have used Super Search to find this answer! :)

--
Laziness, Impatience, Hubris, and Generosity.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (6)
As of 2021-04-17 17:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?