File: timer.h

package info (click to toggle)
gemmi 0.6.5%2Bds-3
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 5,836 kB
  • sloc: cpp: 54,719; python: 4,743; ansic: 3,972; sh: 384; makefile: 73; f90: 42; javascript: 12
file content (25 lines) | stat: -rw-r--r-- 585 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

#include <chrono>
#include <cstdio>

class Timer {
public:
  using Clock = std::chrono::steady_clock;
  Timer(bool enabled) : enabled_(enabled) {}
  void start() {
    if (enabled_)
      start_time_ = Clock::now();
  }
  bool enabled() const { return enabled_; }
  double count() const {
    std::chrono::duration<double> elapsed = Clock::now() - start_time_;
    return elapsed.count();
  }
  void print(const char* msg) const {
    if (enabled_)
      std::fprintf(stderr, "%s %g s.\n", msg, count());
  }
private:
  bool enabled_;
  std::chrono::time_point<Clock> start_time_;
};