On Wednesday, October 15, 2003, at 05:25 PM, Dan Anderson wrote:

But what's the speed concerns here? This is negligable.

Well until applied across the entire program. The program I am working with is significantly longer then the example.

Okay, but in order to write a program, you must include code logic, right? In other words, we can't start leaving out all the Perl parts to make it go faster. The point here is that code is generally not sped up significantly by mucking around with this kind of thing, though Perl is a little more guilty here that most.


If you want to make your code faster, you generally make more progress by attacking your logic than you do Perl's logic. You mention in a later message that that you have over a 1000 if statements. That sounds like a excellent place to start, in my opinion. I have never used anywhere near that many branches for a program logic decision tree. I'm not saying it's not possible you need them, I'm just saying there might be a way to make less choices. Hash look-ups can sometimes help, or grouping categories logically, even if it adds statements, should allow you to drill down faster. Could you post the Cliff Notes version of this if chain so we can see if we can help you find a shortcut or two?

On Wednesday, October 15, 2003, at 05:53 PM, Dan Anderson wrote:

But what's the speed concerns here? This is negligable.

I just double checked and each if statement takes roughly 9.8 microseconds more to execute then an elsif. That may not seem like a lot but over a program spanning several files (perhaps as much as a meg in code when finished) and using thousands of if statements there is a huge difference in the amount of time taken, esp. if it's a web program being used by a number of users simultaneously.

Was that last elsif being reached, or was a choice being made earlier in the chain. If it wasn't getting there, an if statement is just 9.8 microseconds (I stress again, an insanely small amount of time) faster than doing nothing, not an elsif statement. Ever here the expression, "Lies, Damn Lies and Benchmarks"? ;) Careful, here be dragons!


I also triple checked with next statements and I got a really bizarre
result, they were actually slower then just using if elsifs by 17
microseconds.  :: shrugs :: I guess it makes sense -- next involves
extra overhead.

Yes, executing a next() instruction is slower than executing no instruction. ;)


(For what it's worth the experiment was very simple: create 3 perl
scripts, one consisting of 1024 if statements, another consisting of
1023 elsif statements and 1 if, and another with the same and a last at
the end of each (els)if block. I then used $ time ./test.pl for each of
the scripts, and calculated how much power each statement took. (Note
all statements were false)).

Are you familiar with the Devel::DProf and Benchmark modules? This is how we time Perl code. Start here:


perldoc -q profile

Maybe that will get you started.

James


-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to