clock() - perfomance measurement

This is a discussion on clock() - perfomance measurement within the C++ Programming forums, part of the General Programming Boards category; Is the clock() function efective for micro-benchmarks? Or there is another another that is more precise?
Thabk you....

Is the clock() function efective for micro-benchmarks? Or there is another another that is more precise?

Depends what you mean by micro-benchmark. On a non-real-time system you always have a random background latency which makes very small time measurements meaningless. If you can repeat the operation you are trying to measure, the best thing to do is to perform it several thousands or millions of times and find the average time. You can then subtract the average latency, assuming you can measure that.

A lot of systems have a profile timer that increments only while in user code, which makes the measurements a bit more accurate but still probably not accurate enough for events of a microsecond or shorter.