- May
- 13,249
- 181
Trying to work with microsecond precision (and trying to get good accuracy out of it) has led me to discover that the performance counter's frequency isn't rock-steady (no surprise) and may not be what Windows says it is. So I wrote a little app to measure it. Here, the difference between the Windows reported frequency and my measured frequency accounts for a 5.5 second/day drift between the performance counter and the system clock. When I use my measured value in place of the Windows-reported value I can get very accurate absolute times.
My experience has been that measuring the frequency isn't too hard but ...
(1) I can't do it very well in the few seconds Windows has at start-up time, and
(2) I don't get a good measurement on the first try.
That may be due to my lack of knowledge and/or skill, but if Windows must measure it and has those same difficulties, it's no surprise that Windows doesn't get it perfect.
On my two computers I get consistent results like these.
I have attaches a zipped copy of the 32-bit app (all I have right now) in case anyone's curious. I am curious to hear the results of others.
My experience has been that measuring the frequency isn't too hard but ...
(1) I can't do it very well in the few seconds Windows has at start-up time, and
(2) I don't get a good measurement on the first try.
That may be due to my lack of knowledge and/or skill, but if Windows must measure it and has those same difficulties, it's no surprise that Windows doesn't get it perfect.
On my two computers I get consistent results like these.
Code:
l:\projects\perffreq\release> perffreq.exe
Intel(R) Core(TM)2 Quad CPU Q6700 @ 2.66GHz
2597695 is the performanve counter frequency reported by Windows.
Measured frequencies follow, one per minute. Stop with Ctrl-C.
2597532
2597526 (average = 2597529)
2597529 (average = 2597529)
2597529 (average = 2597529)
2597529 (average = 2597529)
2597529 (average = 2597529)
2597529 (average = 2597529)
2597529 (average = 2597529)
2597529 (average = 2597529)
2597529 (average = 2597529)
2597529 (average = 2597529)
2597529 (average = 2597529)
Code:
v:\> perffreq.exe
Intel(R) Xeon(R) CPU E5506 @ 2.13GHz
2083388 is the performanve counter frequency reported by Windows.
Measured frequencies follow, one per minute. Stop with Ctrl-C.
2083246
2083246 (average = 2083246)
2083241 (average = 2083244)
2083248 (average = 2083245)
2083243 (average = 2083245)
2083246 (average = 2083245)
2083234 (average = 2083243)
2083249 (average = 2083244)
2083244 (average = 2083244)
2083244 (average = 2083244)
2083245 (average = 2083244)
2083243 (average = 2083244)
2083246 (average = 2083244)
I have attaches a zipped copy of the 32-bit app (all I have right now) in case anyone's curious. I am curious to hear the results of others.