项目作者: rwpenney

项目描述 :
C++ stopwatch classes for gathering run-time timing statistics
高级语言: C++
项目地址: git://github.com/rwpenney/cxx-rtimers.git
创建时间: 2017-12-21T06:39:51Z
项目社区:https://github.com/rwpenney/cxx-rtimers

开源协议:Mozilla Public License 2.0

下载


C++ run-time timers

This is a set of C++ stopwatch classes for gathering
statistical data on the run-time performance of client code.
The classes will accumulate data on the time taken
for each start/stop interval, and report parameters
such as the minimum, maximum and average time
after the timer goes out of scope.

Features:

  • Header only
  • Templated to allow customization of clock source, timing statistics, etc.
  • C++03 and C++11 (std::chrono) support
  • Scope-based or manual starting/stopping
  • Thread-safe and serial options
  • Numerically stable calculation of mean & standard-deviation statistics
  • Automatic scaling to nanosecond/microsecond/minute/etc. units

Example usage

  1. #include <rtimers/cxx11.hpp>
  2. void expensiveFunction() {
  3. static rtimers::cxx11::DefaultTimer timer("expensive");
  4. auto scopedStartStop = timer.scopedStart();
  5. // Do something costly...
  6. }

When the program terminates, the timer will send a report
of the following form to std:cerr

  1. Timer(expensive): <t> = 8.867us, std = 3.463us, 4.263us <= t <= 57.62us (n=731)

which shows the average time spent within expensiveFunction(),
its standard deviation, the upper and lower bounds,
and the total number of calls.

On POSIX systems with older versions of C++, one could use:

  1. #include <rtimers/posix.hpp>
  2. rtimers::posix::DefaultTimer timer("bottleneck");

Or for systems on which the Boost
libraries are available, including
the boost::posix_time datastructures:

  1. #include <rtimers/boost.hpp>
  2. rtimers::boostpt::DefaultTimer timer("bottleneck");

For multi-threaded code, one can use the following timer classes:

  1. rtimers::cxx11::ThreadedTimer
  2. rtimers::posix::ThreadedTimer
  3. rtimers::boostpt::ThreadedTimer

Preprocessor macros are available for the combined declaration
of a static timer instance and a scoped start+stop:

  1. RTIMERS_BOOST_STATIC_SCOPED(name)
  2. RTIMERS_CXX11_STATIC_SCOPED(name)
  3. RTIMERS_POSIX_STATIC_SCOPED(name)
  4. RTIMERS_STATIC_SCOPED(name)

More specialized timers can be built by combining components
such as rtimers::cxx11::HiResClock, rtimers::SerialManager,
rtimers::MeanBoundStats, rtimers::LogBoundStats,
rtimers::StreamLogger, etc. as illustrated in the
supplied demo.cpp.