[ntp:questions] micro-optimization

David J Taylor david-taylor at blueyonder.neither-this-bit.nor-this.co.uk
Thu Mar 12 09:24:18 UTC 2009

Martin Burnicki wrote:
> David J Taylor wrote:
>> David J Taylor wrote:
>> []
>>> On the Intel 6600 dual-core, 2.4GHz processor here, under XP, a
>>> RDTSC takes about 4.2ns, and a OS call to timeGetTime takes about
>>> 11.8ns. At least, they do if my measurement program is working
>>> correctly....
>>> Haven't checked QPC.
>>> Cheers,
>>> David
>> And QueryPerformanceCounter takes some 226ns.  Oh dear!
> Please keep in mind the QPC function also *tries* to handle the CPU
> specific stuff consistent, if I understand the docs correctly.
> From the Microsoft SDK:
> "On a multiprocessor computer, it should not matter which processor is
> called. However, you can get different results on different
> processors due to bugs in the basic input/output system (BIOS) or the
> hardware abstraction layer (HAL)."
> The latter is obviously the case with some AMD CPUs.
> Anyway, if your code uses RDTSC directly insrtead of QPC then *your
> code* may have to take care about this, and you have to take this
> also into account if you compare execution times.
> Of course I know you can limit these problems using explicite CPU
> affinity.
> Martin

Thanks, Martin.  I was simply reprting the speeds I found, rather than 
attempting to make any comment on which you should call or why.


More information about the questions mailing list