Skip to content

Commit

Permalink
restrict format changes to Duration.
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonDold committed Dec 3, 2023
1 parent 3febdde commit 99d7228
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/search/utils/timer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ using namespace std;

namespace utils {
ostream &operator<<(ostream &os, const Duration &time) {
ios_base::fmtflags original_flags = os.flags();
os << fixed << setprecision(time.output_precision);
os << static_cast<double>(time) << "s";
os.flags(original_flags);
return os;
}

Expand Down Expand Up @@ -111,7 +114,7 @@ Duration Timer::reset() {
}

ostream &operator<<(ostream &os, const Timer &timer) {
os << fixed << setprecision(6) << timer();
os << timer();
return os;
}

Expand Down
1 change: 1 addition & 0 deletions src/search/utils/timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace utils {
class Duration {
double seconds;
public:
static const int output_precision = 6;
explicit Duration(double seconds) : seconds(seconds) {}
operator double() const {
return seconds;
Expand Down

0 comments on commit 99d7228

Please sign in to comment.