IT++ Logo
Using timers to measure execution time

In this example we are using the Real_Timer class to measure the execution time of a simple program. The Real_Timer class is included in the itmisc library.

#include <itpp/itbase.h>
using namespace itpp;
//These lines are needed for use of cout and endl
using std::cout;
using std::endl;
int main()
{
//Declare the scalars used:
long i, sum, N;
//Declare tt as an instance of the timer class:
//Initiate the variables:
N = 1000000;
sum = 0;
//Start and reset the timer:
tt.tic();
//Do some processing
for (i = 0; i < N; i++) {
sum += i;
}
// Print the elapsed time
tt.toc_print();
//Print the result of the processing:
cout << "The sum of all integers from 0 to " << N - 1 << " equals " << sum << endl;
//Exit program:
return 0;
}

When you run this program, the output will look something like this:

Elapsed time = 0.000797055 seconds
The sum of all integers from 0 to 999999 equals 1783293664
itpp::Timer::tic
void tic(void)
Resets the timer and starts it.
Definition: timing.cpp:119
itpp::Timer::toc_print
void toc_print(void)
Prints the elapsed time since last tic()
Definition: timing.cpp:130
itpp
itpp namespace
Definition: itmex.h:36
itbase.h
Include file for the IT++ base module.
itpp::Real_Timer
A real time timer class.
Definition: timing.h:138
itpp::sum
T sum(const Vec< T > &v)
Sum of all elements in the vector.
Definition: matfunc.h:59
SourceForge Logo

Generated on Sat Jun 22 2019 19:10:12 for IT++ by Doxygen 1.8.17