Is the clock() function efective for micro-benchmarks? Or there is another another that is more precise?
Thabk you.
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?
Thabk you.
try gettimeofday() in sys/time.h
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.
A recent thread...
Timing basic operations in C++
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
I support http://www.ukip.org/ as the first necessary step to a free Europe.