Boost logo

Boost :

From: Johan Råde (rade_at_[hidden])
Date: 2008-06-09 15:31:42

dherring_at_[hidden] wrote:
> The CPU timestamp counter is a high-resolution clock source useful for
> profiling code or controlling tight timing loops. AMD/Intel CPUs support
> this via the RDTSC opcode, and other CPUs often provide similar
> functionality.
> Apparently MS compilers support an __rdtsc() intrinsic, but I couldn't
> find one for gcc.

MSVS 8.0 and higher have the __rdtsc intrinsic.

Om earlier versions of MSVC you can use the following inline assembler:

inline uint64_t clockCycleCount()
        uint64_t ccc;
        __asm {
                cpuid // serialize processor
                rdtsc // read time stamp counter
                mov dword ptr [ccc + 0], eax
                mov dword ptr [ccc + 4], edx
        return ccc;

I agree that a platform independent version would be useful.

--Johan Råde

Boost list run by bdawes at, gregod at, cpdaniel at, john at