Thanks to everybody for the responses. The main reason why i posted this why I posted this wasn't to show a statistically significant difference between the three methods (although there does seem to be one). It was more to inquire as to why that difference exists. Certainly we're talking on the order of milliseconds in most programs, as Meryln pointed out.

Nevertheless, using the "context" method as a base, the other methods are 20-40% slower, and I'm not familiar enough with PERL to rationalize that in terms of the internals.

hardburn pointed out that the construction of the @_ variable in the scalar() call is probably a major factor. That seems reasonable, and I could imagine testing it by passing an arrayref to a custom-written version of scalar. But I don't really understand why $#array is so much slower?

-Tats

In reply to Re: Timing of Array-Size Determination Methods by Itatsumaki
in thread Timing of Array-Size Determination Methods by Itatsumaki

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.