Skip to content

Commit 479ad74

Browse files
committed
Vastly simplified IPX timer.h/cc
1 parent 80ca7d9 commit 479ad74

File tree

2 files changed

+6
-24
lines changed

2 files changed

+6
-24
lines changed

highs/ipm/ipx/timer.cc

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff 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-
1410
void 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

highs/ipm/ipx/timer.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,13 @@ namespace ipx {
99
class Timer {
1010
public:
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

1515
private:
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_;
2119
public:
2220
double offset_;
2321
};

0 commit comments

Comments
 (0)