Ruprecht-Karls-Universität Heidelberg

This is an archive of our old website and not updated anymore

The current website can be found at conan.iwr.uni-heidelberg.de

Remarks for time measurement

The different timings

When measuring time with your computer the problem arises that the time a programm needs depends on the load of the system. Are there many processes active a single process gets only few time and runs accordingly long (scheduling by time sharing).

The processor time indicates, how many processor seconds the programm has used. The clock tics as long as the program runs, when the operation system schedules a process to idle, the clock stops.

timer.h

In the header file timer.h are several timing functions implemented, that are capable to read the processor time. The header provides three functions:

  • void reset_timer(struct timeval * timer): reset counter/initialze.
  • double get_timer(struct timeval timer): read used seconds.
  • void print_timer(struct timeval timer): print used seconds.

Download

timer.h

Beispiel

/* Headerfile for time measurement */
#include "timer.h"

int main()
{
  /* variable for time measurement */
  struct timeval timer;
  /* reset counter / initialize */
  reset_timer(&timer);
  // ... do something and utilize processor time ...
  /* print counter */
  print_timer(timer);
}
      

Further information for the details you can find on the manpage for getrusage (2).


Revision: 2242     Letzte Änderung: 2016-10-07 11