The RDTSC (read time-stamp counter) can be used, but on newer processors that do dynamic clock adjustment, the count of clock cycles returned does not reflect an exact duration of time. I suppose dynamic clock adjustment can be disabled, but then on new processors like Nehalem any speed-up advantage is lost. Is there any high-precision, fixed frequency counter available for sub-microsecond time measurement?
Once upon a time I saw someone do a masters thesis benchmarking kernel code using an atomic clock. He could strobe a line that the clock picked up and the clock would record the time. The obvious drawback of this approach is that it requires additional (fairly expensive) hardware, but this may or may not be an issue.
Good question. Its a well recognised problem.
The "solution" is supposedly HPET (High Precision Event Timer) which is/will be/might be included in the processor/chipset of your system. It runs between 10 MHz and 500 MHz.
On Windows, QueryPerformanceCounter() uses the best source available. So this means HPET if its available, RDTSC or another source if not. The only way to tell (that I am aware of) is to calculate its frequency and infer the source.
More info here... this should be simple!!
The other useful bit of info is that although GetSystemTimeAsFileTime() (and other win32 methods) will give you the resolution, if you call it too quickly in succession (<~15mS) it will return the same result due to the way the kernel updates it...