#ifndef CXX_UTIL_STOPWATCH_H #define CXX_UTIL_STOPWATCH_H #include namespace util { class stopwatch { public: typedef long long usec_t; stopwatch() : start_(now()) {} usec_t elapsed() const { return now() - start_; } usec_t reset() { usec_t t(now()); usec_t r(t - start_); start_ = t; return r; } private: static usec_t now() { timeval t; ::gettimeofday(&t, 0); return 1000000LL * t.tv_sec + t.tv_usec; } private: usec_t start_; }; } // namespace util #endif // CXX_UTIL_STOPWATCH_H