in reply to OT How fast a cpu to overwhelm Time::HiRes
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: OT How fast a cpu to overwhelm Time::HiRes
by tirwhan (Abbot) on Nov 30, 2005 at 16:22 UTC | |
by BrowserUk (Patriarch) on Nov 30, 2005 at 17:06 UTC | |
by tirwhan (Abbot) on Dec 01, 2005 at 00:42 UTC | |
by BrowserUk (Patriarch) on Dec 01, 2005 at 01:54 UTC | |
by tirwhan (Abbot) on Dec 01, 2005 at 09:45 UTC | |
|