Posted By

jimfred on 05/08/09


Tagged


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

khouser


Simple stopwatch class to measure duration using clock() and CLOCKS_PER_SEC in time.h


 / Published in: C++
 

non-dot.net, c++ Windows

  1. // stopwatch - Implements CStopWatch, used to debug timing.
  2.  
  3. #pragma once
  4. #include <time.h>
  5.  
  6. class CStopWatch
  7. {
  8. private:
  9. clock_t start;
  10. clock_t finish;
  11.  
  12. public:
  13. double GetDuration() { return (double)(finish - start) / CLOCKS_PER_SEC; }
  14. void Start() { start = clock(); }
  15. void Stop() { finish = clock(); }
  16.  
  17. }; // class CStopWatch

Report this snippet  

You need to login to post a comment.