Wednesday, 22 June 2016

RDTSC: Read Time-Stamp Counter

rdtsc is a real time stamp counter that returns  the number of clock ticks from the time the system was last reset.
The rdtsc instruction returns the time stamp counter in EDX:EAX.

This instruction is useful when you want to measure the performance of a certain code or application in clock ticks, or compare the performance of two programs, which are too small to be counted in seconds.

Here is a sample C code that shows how you can make use of this instruction.


#include
#include
#include
#include
#include


void example() {

uint64_t tick1, tick2; //unsigned 64 bit quantity

unsigned c,d;

asm volatile("rdtsc" : "=a" (c), "=d" (d));  //assembly code running the instruction                        
                                                                  //rdtsc

tick1 = (((uint64_t)c) | (((uint64_t)d) << 32)); // calculating the tick value.

printf("time %llu",tick1);


}

No comments:

Post a Comment