Read time stamp counter in C

by Gregor Uhlenheuer on May 31, 2010

While searching for a method to benchmark/profile some functions in C I stumbled upon the RDTSC 1. The TSC is a specific register available at least on x86 processors since the Pentium which counts the processor ticks since reset. The TSC is returned on the RDTSC call (opcode 0F 31) in EDX:EAX.

The following C function worked for me on x86_64 linux:


  1. Read Time Stamp Counter

This post is tagged with c, cpu, profiling and programming