4

I was trying to figure out if there is any easy method to convert the CPU cycles obtained in C using rdtsc() function into time in seconds.

ex:-

unsigned long long start, stop;

start = rdtsc();
stop = rdtsc();

printf(" CPU CYCLES: %llu\n", b-a);

is there any possible way to convert this into time in seconds?

Déjà vu
  • 28,223
  • 6
  • 72
  • 100
nk134
  • 43
  • 1
  • 7
  • Also see this https://stackoverflow.com/questions/42189976/calculate-system-time-using-rdtsc – Dmitriy Dec 10 '17 at 01:27
  • 2
    In particular, see the (currently) [second answer](https://stackoverflow.com/a/42190816/298225) in the question [Dmitriy](https://stackoverflow.com/users/5455223/dmitriy) links above. Intel changed how the TSC behaves. In current processors, it is not a CPU-cycle counter. And “CPU cycles to seconds” is not meaningful in processors that change their frequency depending on temperature and other factors. This may be an [XY problem](https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem). What do you really want to get—wall clock time, number of CPU cycles, or something else? – Eric Postpischil Dec 10 '17 at 01:52

0 Answers0