- /* timer.h by K.Tsuru */
- /*******************************************************************************
- Timer class
- Includes ANSI C/C++ functions only.
- Precision is about 1/CLOCKS_PER_SEC sec or 1.0 sec after 1000.0 secs.
- Parallel measurements within ten are available.
- reference : C Magazine 1993, No.9 pp.49-55(in Japanese)
- [Notice]
- On GNU/Linux the "LapTime()" function is reset (return a negative value) after
- about 2,100 secs using "clock()" function. Perhaps an overflow occurs. Then it
- uses "time()" function after 1000 secs which provides an enough effective figures.
- ********************************************************************************/
- #ifndef TIMER_H
- #define TIMER_H
-
- #include <stdlib.h>
- #include <time.h>
-
- const int maxTimer = 10;
-
- class Timer {
- public:
- enum timer { START, STOP, LAP };
- private:
- static double unitSecond;
- static double lossTime[maxTimer];
- static int timerObjects;
- bool active;
- int objectID;
- double startClock;
- time_t startTime;
- bool usesClock; // uses clock() or time()
- double StopWatch(timer sw);
- void GetUnitSecond();
- double WaitTick(double* lt);
- public:
- time_t Start();
- double LapTime();
- double Stop();
- int ID() const { return objectID; }
- bool UsesClock() const { return usesClock; }
- double UnitSecond() const { return unitSecond; }
- Timer(bool start = false);
- ~Timer();
- };
-
- inline time_t Timer::Start(){
- active = true; StopWatch(START);
- return startTime; // add cast since ver 2.19
- }
- inline double Timer::Stop(){
- double t = StopWatch(STOP);
- active = false; lossTime[objectID] = 0.0;
- return t;
- }
- inline double Timer::LapTime(){
- return StopWatch(LAP);
- }
- #endif // TIMER_H
timer.h : last modifiled at 2017/04/06 15:30:01(1,723 bytes)
created at 2016/04/11 11:18:59
The creation time of this html file is 2017/10/11 16:07:52 (Wed Oct 11 16:07:52 2017).