#ifndef _SYSTIMER_H #define _SYSTIMER_H // systimer.h // // July 3, 1996 // David Levine, Chris Nevison // // (modified format on 5/20/97, Owen Astrachan) // // This file specifies a timer class. The purpose of this class is to // permit the programmer to measure the amount of system time which is // spent during particular phases of a program. The general model for // this timer class was taken from _A Computer Science Tapestry_ by // Owen Astrachan, McGraw-Hill, ISBN 0-07-002036-1. // // The basic model of the class is that of a stop watch which has two // buttons. One button is used to toggle the stop watch between the // "recording" and "idle" states and the other button is used to reset // the stop watch. // // Concerning units: All times are given in units of seconds returned // as a double. // // The class is based in the C library function clock(), which returns // the number of ticks of the system clock since the program started, // where the system constant CLOCKS_PER_SEC specifies the number of // ticks per second. This constant determines the smallest time // differential which can be measured, ranging from a few microseconds // to more than a hundredth of a second. This smallest time difference // is returned by the function granularity. // // On some systems the constant CLK_TCK may be used // instead of CLOCKS_PER_SEC, in which case the line after the // includes should be uncommented. //#include "bool.h" #include // const CLOCKS_PER_SEC CLK_TCK; class SysTimer { public: SysTimer(); // constructor // methods to modify the state of the stopwatch void start(); // begin timing void stop(); // stop timing void reset(); // reset timer to 0; stops watch if running // methods to query the stopwatch bool isRunning() const; // true iff stopwatch is running double lapTime() const; // number of microseconds since start double elapsedTime() const; // microseconds between start and stop double cumulativeTime() const; // returns time since last reset double granularity() const; // returns smallest measurable time private: bool amRunning; // true iff stopwatch is currently running clock_t myStartTime; // holds the last time the watch was started clock_t myElapsed; // holds the time between the last start // and the last stop clock_t myCumulative; // holds the total amount of time that the // stopwatch has been on since the last reset // (except for the current "lap" time) }; #endif