Microsecond accurate (or better) process timing in Linux

后端 未结 8 2445
醉话见心
醉话见心 2020-12-14 04:01

I need a very accurate way to time parts of my program. I could use the regular high-resolution clock for this, but that will return wallclock time, which is not what I need

8条回答
  •  爱一瞬间的悲伤
    2020-12-14 04:47

    See this question for some more info.

    Something I've used for such things is gettimeofday(). It provides a structure with seconds and microseconds. Call it before the code, and again after. Then just subtract the two structs using timersub, and you can get the time it took in seconds from the tv_usec field.

提交回复
热议问题