|We don't bite newbies here... much|
Re^2: Question about curious performance of if...elsif blockby markseger (Beadle)
|on Jan 16, 2012 at 18:07 UTC||Need Help??|
>First of all, you're talking about a time-difference, but there's no context. The difference between 0.01 and 1.01 seconds is far more interesting than the difference between 15h36m55s and 15h36m56s.
I have a very large perl script (on the order of 10K lines of code). This is something that takes about 1-1/2 minutes overall to execute. does this help with the context?
I was looking more closely at some of the execution paths for opportunities of optimization and was wondering what benefit there would be to order the options in some big if...elsif blocks more carefully ordered and thought that it might be so I did some experiments
BUT if a 1M compares takes <1sec as it does with my first test script, it's probably not as significant as I thought, but 5 seconds with the second scrpipt begins to get my attention.
>Second, your first talk about a difference of 3/4 of a second, then of a difference of 5. There's quite a difference in differences.
That's my point but I guess I didn't phrase the question properly, so let me try again.
In the first case what I'm trying to say is that to run that block of the 10 if...elsif... statements 1M times, takes about 3/4 of a second, the difference being that between the time it takes to execute them vs not-execute them.
However, when that identical block of code is run in the second script it takes over 7 times longer. THAT is my question - why?
>Third, without the return, you're doing 10 comparisons in an otherwise almost empty sub (the first time the sub is called, memory needs to be allocated, but Perl doesn't throw it away, making that in any subsequent call to the sub, the assignment to $a is relatively cheap), so I do expect there to be a difference.
Agreed and as I said above, that difference is the time takes to execute the 10 comparisons.
>Fourth, use the NYTProf profiler, and see how much time each statement takes.
I know, I was being lazy, but given the dramatic differences in the times I'd thing even my coarser level of analysis should be valid.