Note: This tutorial assumes that you have completed the previous tutorials: Stopwatch.
(!) Please ask about problems and questions regarding this tutorial on Don't forget to include in your question the link to this page, the versions of your OS & ROS, and also add appropriate tags.


Description: Tools to assist benchmarking programs.

Tutorial Level: INTERMEDIATE


/!\ Requires : librt

This is a variation of the stopwatch for systems with librt. The time measured by the cpu watch is not system time, rather the time spent by the process actually exeucting on the cpu. This is very useful for benchmarking programs. Usage is exactly the same as for the stopwatch class.


It is useful when used with the TimeData class - this class helps store timings from a CpuWatch and then analysing them with some statistical methods.

   1 CpuWatch cpuwatch;
   2 TimeData timings;
   3 ecl::Duration duration;
   4 for ( unsigned int i = 0; i < 100; ++i ) {
   5     cpuwatch.restart();
   6     // do some work here
   7     duration = cpuwatch.split();
   8     timings.push_back(duration);
   9 }
  10 std::cout << "Average : " << timings.average() << std::endl;
  11 std::cout << "Variance: " << timings.variance() << std::endl;

Wiki: ecl_time/Tutorials/Benchmarking (last edited 2012-01-31 15:16:09 by DanielStonier)