Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Efficiency of multiple if statements (code)

by deprecated (Priest)
on May 09, 2001 at 01:18 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://78963]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2024-04-24 08:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found