0

I am trying to measure the time taken to run certain functions in my code. Since using RDTSC is most efficient, I would like to use this. However, I couldn't understand how to implement this.

Can someone please provide an example as to how we would implement this in code(C Language) and convert the number of cycles to milliseconds? Like for example, measuring the time it takes to do a read from the file.

I couldn't find much explanations on the implementation, but found only definitions.

Thank you.

too honest for this site
  • 12,050
  • 4
  • 30
  • 52
Sal
  • 15
  • 7
  • By googling "example use RDTSC to time code execution C" I found [this previous question](http://stackoverflow.com/questions/29189935/rdtsc-timing-for-a-measuring-a-function), and others, fairly quickly. Although timing to cycle precision is not necessarily the best or easiest way to time the execution on a modern OS, which is probably unrepeatable to that accuracy. – Weather Vane Apr 18 '17 at 17:36
  • This paper describes the inline asm to add in C: [How to Benchmark Code Execution Times on Intel® IA-32 and IA-64 Instruction Set Architectures](https://www-ssl.intel.com/content/dam/www/public/us/en/documents/white-papers/ia-32-ia-64-benchmark-code-execution-paper.pdf) Right there on p16. It's pretty straightforward if your cpu supports constant_tsc , which you can check with `cat /proc/cpuinfo` and looking in the 'flags' field. – Don Slowik Jun 14 '17 at 20:47

0 Answers0