Go to the source code of this file.
Classes | |
class | stopwatch |
Enumerations | |
enum | time_type { USER_TIME, SYSTEM_TIME, ABSOLUTE_TIME } |
Definition in file stopwatch.h.
enum time_type |
The following class implements a stopwatch. You may have more than one stopwatch running without any interference and without any additional computational work. The clock interrupt has a frequency of 100 Hz (this is stated by the macro HZ, in /usr/include/asm/params.h). The value of the clock is stored in the tms_utime field of the struct tms (in the file /usr/include/sys/times.h), and is of type clock_t (a long int defined in /usr/include/bits/types.h). Since a long int has 32 bits (/usr/include/values.h) it follows that the clock should have the same value after 2^32/100 secs, that is 715828 minutes (497 days). Since clock_t is a long int (and not an "unsigned long int") we don't have to worry about when the wrapping occurs. Suppose, for example that you start your stopwatch at MAXLONG and stop it at MINLONG+10, then (MINLONG+10) - MAXLONG = 11 (correct! 11 ticks passed).
EXAMPLE OF USE:
stopwatch* stop = new stopwatch(); stop->start(); ... ... HEAVY OPERATIONS HERE ... cout.form("computational time = %f secs\n",stop->get()); delete(stop);
Definition at line 36 of file stopwatch.h.