Code snippets‎ > ‎C++‎ > ‎

Timing

Intel TBB

The file below is supposed to use the most accurate timer available on the platform. It is adapted from Intel TBB to be used as a stand-alone header file.

Standard library - std

http://www.cplusplus.com/reference/clibrary/ctime/clock/


clock_t clock ( void );

Clock program Returns the number of clock ticks elapsed since the program was launched.

The macro constant expression CLOCKS_PER_SEC specifies the relation between a clock tick and a second (clock ticks per second).

The initial moment of reference used by clock as the beginning of the program execution may vary between platforms. To calculate the actual processing times of a program, the value returned by clock should be compared to a value returned by an initial call to clock.


#include <ctime> 

int main() {
  std::clock_t start = std::clock();
  std::clock_t stop = std::clock(); 
  double diff = (stop-start)/(double)CLOCKS_PER_SEC;
  std::cout << "Elapsed time " << diff << "s" << std::endl;
}



boost - C++ libraries

http://www.boost.org/doc/libs/release/libs/timer/index.html


#include <boost/timer.hpp>

boost::timer t;
double diff = t.elapsed();
t.restart;


ċ
tick_count.h
(5k)
Nico Kruithof,
Aug 23, 2013, 7:12 AM
Comments