How to accurately measure clock cycles used by a c++ function?
I know that I have to use: rdtsc. The measured function is deterministic but the result is far from being repeatable (I get 5% oscillations from run to run). Possible causes are: context switching cache misses Do you know any other causes? How to eliminate them? TSCs (what rdtsc uses) are often not synchronized on multi-processor systems. It may help to set the CPU affinity in order to bind the process to a single CPU. You could also get timestamps from HPET timers if available, which aren't prone to the same problem. As for repeatability, those variances are true. You could disable caching,