From a functional perspective this produces the correct result but from a performance perspective it may not. If in the actual code there is only one pass over the array then setting pos is not required. In such a case it is only required for the benchmark. As setting pos takes time that will not be required in the real code, it introduces an error in the benchmark results.

An interesting case is if I want to compare the times with and without pos being set, yet always with the same initial conditions, to learn how much impact setting pos has. This can't be determined without isolating the iterations from each other. Then we are back to the possibility that time to initialize obscures the differences in the code under test.

My apologies for being so fussy - it is not that I don't appreciate your suggestions. I am trying to measure the performance of particular code in isolation and with strictly controlled initial conditions.


In reply to Re^4: Initializing iterations while benchmarking by ig
in thread Initializing iterations while benchmarking by ig

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.