LinuxQuestions.org

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

crudbug 09-19-2010 09: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 11:49 AM

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 03:09 PM.