Measuring elapsed CPU time / equivalent to clock()?

I want to measure the total CPU time elapsed. I do not believe that I use any multi-threaded operation. In Python I would use time.clock() for this; in C, clock(). I have looked at @time and @elapsed macros but they do not work for me for two reasons:

  • they measure wall time
  • they do not provide the time elapsed since the program started. time_ns() does that but for wall time.

So basically I would like something like time_ns() but for CPU time rather than wall time. Is there a function that provides this functionality? If not, how should I go about writing one?

You might want to take a look at


Thank you, don’t know how I missed that, CPUtime_us() is what I need!