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?? |
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! :) --
In Section
Seekers of Perl Wisdom
|
|