Johannes Lampel - Projects/HPTime
I wrote this class for more exact time measurements than it was possible using the standard time functions that come with your C/C++ compiler. It is based on the RDTSC asm command which reads out a CPU internal 64 bit counter which is incremented with each clock cycle.
When this class is instantiated, it first detects your cpu speed
using QueryPerformanceCounter on windows or ftime on linux.
Usually this class is instantiated as a global variable, i.e. you only need
this initialization once, since this measurement takes some time. You can get
the number of cycles the CPU is already running as an 64 bit integer value or
as a double precision floating point value indicating the seconds the CPU runs.
Please note that when measuring clockwise some periods of time, you have to
bear in mind, that programs on a multitasking operating system are not run parallel,
but they are given tiny time slices. That means that you shouldnt worry about
peaks in your measurements, or try to filter them out.
Because of the size of the counter of 64bit you don't have to worry about overflows
in a reasonable time, at least on current CPUs.