> 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


In reply to Re^6: Question about curious performance of if...elsif block by markseger
in thread Question about curious performance of if...elsif block by markseger

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.