00001
00023 #ifndef GALOIS_TIMER_H
00024 #define GALOIS_TIMER_H
00025
00026 #include "Galois/config.h"
00027
00028 #ifdef HAVE_CXX11_CHRONO
00029 #include <chrono>
00030 #endif
00031
00032 namespace Galois {
00033
00034 #ifdef HAVE_CXX11_CHRONO
00035 class Timer {
00036 typedef std::chrono::steady_clock clockTy;
00037
00038 std::chrono::time_point<clockTy> startT, stopT;
00039 public:
00040 void start() { startT = clockTy::now(); }
00041 void stop() { stopT = clockTy::now(); }
00042 unsigned long get() const {
00043 return std::chrono::duration_cast<std::chrono::milliseconds>(stopT-startT).count();
00044 }
00045 unsigned long get_usec() const {
00046 return std::chrono::duration_cast<std::chrono::microseconds>(stopT-startT).count();
00047 }
00048 };
00049 #else
00051 class Timer {
00052
00053
00054 unsigned long _start_hi;
00055 unsigned long _start_low;
00056 unsigned long _stop_hi;
00057 unsigned long _stop_low;
00058 public:
00059 Timer();
00060 void start();
00061 void stop();
00062 unsigned long get() const;
00063 unsigned long get_usec() const;
00064 };
00065 #endif
00066
00069 class TimeAccumulator {
00070 Timer ltimer;
00071 unsigned long acc;
00072 public:
00073 TimeAccumulator();
00074 void start();
00076 void stop();
00077 unsigned long get() const;
00078 TimeAccumulator& operator+=(const TimeAccumulator& rhs);
00079 TimeAccumulator& operator+=(const Timer& rhs);
00080 };
00081
00082 }
00083 #endif
00084