http://www.perlmonks.org?node_id=948203


in reply to Re^5: Question about curious performance of if...elsif block
in thread Question about curious performance of if...elsif block

> No. Because it would not run here. ahh, so I guess you're not running linux.

no problems. here's a run with the subroutine call commented out:

[root@poker collectl]# time ./test.pl real 0m14.464s user 0m5.089s sys 0m9.087s
now with the call executing BUT the return statement executing first thing in the subroutine:
[root@poker collectl]# time ./test.pl real 0m19.508s user 0m10.461s sys 0m8.853s
so clearly the overhead in calling the subroutine 1M times is about 5-1/2 seconds. Now I'll comment out the early return in the subroutine in the subroutine and run it again:
[root@poker collectl]# time ./test.pl real 0m25.648s user 0m16.350s sys 0m9.123s
This says to me the if...elsif... takes about 6 seconds and I can't fathom why! Could there be some weird interaction going on between perl/linux and the /proc filesystem?

As I said in my base note I'm not an innards kind of a guy but it feels like something that is not going to show up in every perl script. Rather if feels like there is some kind of weird interraction.

and speaking of environment this is rhel5.3 and perl 5.8.8. I just tried the code again on rhel6.2 in a VM with perl 5.10, and the differences between the last 2 runs are:

real 0m7.359s user 0m2.840s sys 0m4.481s real 0m9.782s user 0m5.082s sys 0m4.615s real 0m11.927s user 0m7.266s sys 0m4.604s
so in this case both the subroutine calls and the if...elsif... block are only taking a little over 2 seconds each. This says to me there is something more efficient going on with 5.10.

Perhaps this is less of a big deal as 2 extra seconds is getting less of a concern, but I still an curious about what exactly is going on.

-mark

Replies are listed 'Best First'.
Re^7: Question about curious performance of if...elsif block
by bulk88 (Priest) on Jan 18, 2012 at 13:55 UTC
    Have you tried using B::Concise "perl -MO=Concise,-exec,-src" on your scripts?
Re^7: Question about curious performance of if...elsif block
by jethro (Monsignor) on Jan 19, 2012 at 10:21 UTC

    Remember that a processor is a complex beast. For example your bigger script might just have exceeded the small L1 instruction cache of your processsor, which is just 32k on a core2 CPU.