stopwatch.hpp 675 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #include <unistd.h>
  2. #include <sys/times.h>
  3. #include <sys/types.h>
  4. #include <stdlib.h>
  5. class Time
  6. {
  7. public:
  8. Time():mTicksPerSec(sysconf(_SC_CLK_TCK)), mRealTime(0){mTmsTime.tms_utime=0; mTmsTime.tms_stime=0;}
  9. void getCurrentTime() {mRealTime = times(&mTmsTime);};
  10. Time& subtract(const Time& Subtrahent);
  11. Time operator-(const Time& Subtrahent) const;
  12. void print();
  13. private:
  14. long mRealTime;
  15. struct tms mTmsTime;
  16. long mTicksPerSec;
  17. };
  18. class StopWatch
  19. {
  20. public:
  21. StopWatch();
  22. void start();
  23. void stopRound();
  24. void stop();
  25. private:
  26. Time mStartTime;
  27. Time mStopTime;
  28. Time mLastStopTime;
  29. int mRounds;
  30. };