fast elapsed time on linux

2019-01-23 07:50发布

I am looking for a fast way to get the elapsed time between two calls of a function in C.

I considered using jiffies, but they are not available in userland. So, should I use getimeofday() or is there any fastest way to do this.

I am only interested in the elasped time between two calls, to use in a benchmark tool.

标签: c linux time
7条回答
Anthone
2楼-- · 2019-01-23 08:16

Yes, gettimeofday() would suffice if you want to find the actual elapsed. If you need to find the CPU time, then you can use clock(). In many cases, both approach would give similar result (unless there is a sleep or some sort of wait in code). An example of clock() can be found here:
http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_19.html

查看更多
登录 后发表回答