File tree Expand file tree Collapse file tree 2 files changed +6
-24
lines changed
Expand file tree Collapse file tree 2 files changed +6
-24
lines changed Original file line number Diff line number Diff line change @@ -7,26 +7,10 @@ Timer::Timer(const double offset)
77 Reset (true );
88}
99
10- double Timer::Elapsed () const {
11- return toc (t0_);
12- }
13-
1410void Timer::Reset (const bool first) {
15- if (!first)
16- offset_ -= duration_cast<duration<double >>(t0_.time_since_epoch ()).count ();
17- t0_ = tic ();
18- if (!first)
19- offset_ += duration_cast<duration<double >>(t0_.time_since_epoch ()).count ();
20- }
21-
22- Timer::TimePoint Timer::tic () {
23- return high_resolution_clock::now ();
24- }
25-
26- double Timer::toc (TimePoint start) {
27- TimePoint end = tic ();
28- duration<double > diff = end-start;
29- return diff.count ();
11+ if (!first) offset_ -= t0_;
12+ t0_ = read ();
13+ if (!first) offset_ += t0_;
3014}
3115
3216} // namespace ipx
Original file line number Diff line number Diff line change @@ -9,15 +9,13 @@ namespace ipx {
99class Timer {
1010public:
1111 Timer (const double offset=0 );
12- double Elapsed () const ;
12+ double Elapsed () const { return toc (t0_); }
1313 void Reset (const bool first = false );
1414
1515private:
16- typedef time_point<high_resolution_clock> TimePoint;
17- static TimePoint tic ();
18- static double toc (TimePoint start);
16+ static double toc (double start) { return read () - start; }
1917 static double read () { return duration_cast<duration<double >>(high_resolution_clock::now ().time_since_epoch ()).count (); }
20- TimePoint t0_;
18+ double t0_;
2119public:
2220 double offset_;
2321};
You can’t perform that action at this time.
0 commit comments