next up previous contents
Next: handlers Up: Description of the Previous: rational_factorization

timer


timer timer class


timer is a class of timer utilities. It can be used for example to calculate the elapsed time during a function, the time spent in the system and the time spent in the execution of the function.


timer is a class which simulates the functions of a chronometer. An instance T of the data type timer is an object consisting of the integer variables user_time , sys_time and local variables which are used to store elapsed times.

A possible scenario of the use of timer is to start it at any place of the program then stop it at and print the elapsed real , system and user time between and . Continuing the timing and stopping the timer once again at stores in T the sum of the elapsed times between and and

and .

Constructors/Destructor

timer()

timer()

Initialization

int T.set_print_mode(int m)

this function sets the output mode m of the print()

function (see below) for T and returns the old print mode. There are two predefined output modes: TIME_MODE and HMS_MODE . The output of the print() function when TIME_MODE is set, has the following format: rrr real uuu user sss sys ,

where rrr, uuu, sss denote the real, user and system time respectively (in 1/100 sec). In HMS_MODE the print() function outputs the elapsed real time in the format hhh hour, mmm min, nnn sec, ttt ms ,

where hhh, mmm, nnn and ttt denote the consumed hours, minutes, seconds and milliseconds respectively.

void T.start_timer()

this function initializes the timer with the current time and sets the elapsed time for this timer to zero.

Access Functions

int T.get_print_mode()

returns the output mode of the timer T . This mode is used by the print() function (see below).

long T.user_time()

returns the user time elapsed during the last call of start_timer() . The time is given in 1/100 seconds.

long T.sys_time()

returns the system time elapsed during the last call of start_timer() . The time is given in 1/100 seconds.

long T.real_time()

returns T.user_time() + T.sys_time() .

High-Level Functions

void T.stop_timer()

this function adds in T the elapsed time (user + system) since the last call of start_timer() or cont_timer() .

void T.cont_timer()

this function sets the starting point for timing to the current time without changing the elapsed time in T .

Input/Output

The ostream operator << is overloaded. Furthermore there exists the following member function for output:

void T.print()

prints the timings elapsed between the last subsequent calls of T.start_timer() and T.stop_timer()

according to the print mode of T.


getrusage(2)


Subsequent calls of stop_timer() produce wrong results.


#include <LiDIA/timer.h>

int main()
{
  long i;
  timer x;

  x.set_print_mode(HMS_MODE);

  x.start_timer();
  for (i=0; i < 0x7fffff; i++);
  x.stop_timer();
  cout << endl;
  x.print();
  cout << endl;
  x.cont_timer();
  for (i=0; i < 0x7fffff; i++);
  x.stop_timer();
  cout << endl;
  x.print();
  cout << endl;
}

An extensive example of timer can be found in LiDIA 's installation directory under

src/system/timer_appl.c


Thomas Papanikolaou

Copyright 1995 by the LiDIA -Group, Universität des Saarlandes



next up previous contents
Next: handlers Up: Description of the Previous: rational_factorization



LiDIA Administrator
Thu Aug 10 16:41:08 MET DST 1995