LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   How to convert TSC cpu cycles into seconds in C? (http://www.linuxquestions.org/questions/programming-9/how-to-convert-tsc-cpu-cycles-into-seconds-in-c-833190/)

crudbug 09-19-2010 10:20 AM

How to convert TSC cpu cycles into seconds in C?
 
main()
{
unsigned long long tsc_start, tsc_end;
tsc_start = get_tsc();
// execute some code

tsc_end = get_tsc();
printf("Total time for execution %llu cpu cycles", tsc_end - tsc_start);
printf("Total time in seconds "); // How to compute this ?
}

static unsigned long long get_tsc()
{
unsigned long long tsc;
asm volatile ("rdtsc" : "=A" (tsc));
return tsc;
}

Wim Sturkenboom 09-19-2010 12:49 PM

maybe this is of help : http://www.unix.com/programming/81639-rdtsc-use-c.html

And please use code tags [code]your code here[/code] when posting code


All times are GMT -5. The time now is 09:44 PM.