00001 #ifndef COMPONENTS_C11TIMER_H 00002 #define COMPONENTS_C11TIMER_H 00003 00004 #include <chrono> 00005 00006 #include <casa/namespace.h> 00007 00008 namespace casa { 00009 00010 class C11Timer { 00011 // <summary> 00012 // Timer based on C++11 chrono library 00013 // </summary> 00014 00015 // <reviewed reviewer="" date="" tests="" demos=""> 00016 // </reviewed> 00017 00018 // <prerequisite> 00019 // </prerequisite> 00020 00021 // <etymology> 00022 // Timer based on C++11 chrono library 00023 // </etymology> 00024 00025 // <synopsis> 00026 // Timer based on C++11 chrono library 00027 // </synopsis> 00028 00029 public: 00030 // create the timer but do not start it. 00031 C11Timer(); 00032 00033 ~C11Timer(); 00034 00035 // return mean duration, in seconds, of all start/stop cycles 00036 Double meanDuration() const; 00037 00038 // duration in seconds of most recent start/stop cycle 00039 Double duration() const; 00040 00041 // number of start/stop cycles 00042 uInt nCycles() const; 00043 00044 // (re)start the timer 00045 void start(); 00046 00047 // stop the timer 00048 void stop(); 00049 00050 // total duration in seconds, sum of all start/stop cycles 00051 // doesn't include the duration of the current cycle if the 00052 // timer is currently running 00053 Double totalDuration() const; 00054 00055 private: 00056 std::chrono::steady_clock::time_point _start; 00057 std::chrono::duration<double> _duration, _totalDuration; 00058 uInt _nCycles; 00059 00060 00061 }; 00062 } 00063 00064 #endif