00001 #ifndef __SCOPED_TIMER_H 00002 #define __SCOPED_TIMER_H 00003 00009 #include "TimeUtil.h" 00010 00026 class ScopedTimer { 00027 public: 00036 ScopedTimer(uint64_t& t, bool enabled = true) : 00037 timer(t), start(enabled ? TimeUtil::timeu() : 0), enabled(enabled) { } 00039 ~ScopedTimer() { 00040 if (enabled) { 00041 timer += TimeUtil::timeu() - start; 00042 } 00043 } 00044 00045 private: 00046 uint64_t& timer; 00047 uint64_t start; 00048 bool enabled; 00049 }; 00050 00055 #endif