1. /* timer.h by K.Tsuru */
  2. /*******************************************************************************
  3. Timer class
  4. Includes ANSI C/C++ functions only.
  5. Precision is about 1/CLOCKS_PER_SEC sec or 1.0 sec after 1000.0 secs.
  6. Parallel measurements within ten are available.
  7. reference : C Magazine 1993, No.9 pp.49-55(in Japanese)
  8. [Notice]
  9. On GNU/Linux the "LapTime()" function is reset (return a negative value) after
  10. about 2,100 secs using "clock()" function. Perhaps an overflow occurs. Then it
  11. uses "time()" function after 1000 secs which provides an enough effective figures.
  12. ********************************************************************************/
  13. #ifndef TIMER_H
  14. #define TIMER_H
  15. #include <stdlib.h>
  16. #include <time.h>
  17. const int maxTimer = 10;
  18. class Timer {
  19. public:
  20. enum timer { START, STOP, LAP };
  21. private:
  22. static double unitSecond;
  23. static double lossTime[maxTimer];
  24. static int timerObjects;
  25. bool active;
  26. int objectID;
  27. double startClock;
  28. time_t startTime;
  29. bool usesClock; // uses clock() or time()
  30. double StopWatch(timer sw);
  31. void GetUnitSecond();
  32. double WaitTick(double* lt);
  33. public:
  34. time_t Start();
  35. double LapTime();
  36. double Stop();
  37. int ID() const { return objectID; }
  38. bool UsesClock() const { return usesClock; }
  39. double UnitSecond() const { return unitSecond; }
  40. Timer(bool start = false);
  41. ~Timer();
  42. };
  43. inline time_t Timer::Start(){
  44. active = true; StopWatch(START);
  45. return startTime; // add cast since ver 2.19
  46. }
  47. inline double Timer::Stop(){
  48. double t = StopWatch(STOP);
  49. active = false; lossTime[objectID] = 0.0;
  50. return t;
  51. }
  52. inline double Timer::LapTime(){
  53. return StopWatch(LAP);
  54. }
  55. #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).