I seriously doubt that it is possible to get two identical timestamps from Time::HiRes on a single CPU system. At least not under Win32, and I doubt it is much different under other OSs.

Under Win32, the mechanism underlying the timestamps is the QueryPerformanceCounter() API. It has a companion call, QueryPerformanceFrequency() which tells you how quickly the raw timer changes. On my 2.66 GHz system, this frequency is reported as 3579545 ticks/second. This second call is required because the speed of the counter underlying the timing mechanism is tied to the speed of the processor. As the processor gets faster, so does the counter.

Calling the api directly from within Perl, I get

P:\test>perl qpc.pl t/S: 3579545 Ticks1: 4139490207899 Ticks2: 4139490207925 Diff : 26 P:\test>perl qpc.pl t/S: 3579545 Ticks1: 4139494180449 Ticks2: 4139494180475 Diff : 26 P:\test>perl qpc.pl t/S: 3579545 Ticks1: 4139496939489 Ticks2: 4139496939517 Diff : 28 P:\test>perl qpc.pl t/S: 3579545 Ticks1: 4139500850229 Ticks2: 4139500850256 Diff : 27

Showing that even bypassing the code in Time::HiRes, 2 consecutive calls take at least 25 ticks. On my system that translates into approximately 25 / 3579545 = 0.00000698 seconds, or at 2.66GHz, roughly 18500 cpu cycles. On modern processors, that can often equate to 18500 cpu instructions.

If I drop into C

P:\test>qpc Frequency: 3579545 T1: 823060571 T2: 823060575 P:\test>qpc Frequency: 3579545 T1: 829532517 T2: 829532521 P:\test>qpc Frequency: 3579545 T1: 833572712 T2: 833572716

The closest I get is 4 ticks, or roughly 0.0000011 seconds or 3000 cpu cycles/instructions.

Whilst there are many faster processors than mine, the salient point is that as the processor gets faster, the frequency of the counter will also increase.

So the possibility for you being able to get two identical timestamps from within Perl on a single processor system, given the extra cycles that getting from perl to the hardware and back again involves, seems pretty unlikely.

YMMV on other OSs and hardware.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

In reply to Re: OT How fast a cpu to overwhelm Time::HiRes by BrowserUk
in thread OT How fast a cpu to overwhelm Time::HiRes by zentara

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.