Chebyshev
Unit testing for scientific software
timer.h
Go to the documentation of this file.
1 
5 
6 #ifndef CHEBYSHEV_TIMER_H
7 #define CHEBYSHEV_TIMER_H
8 
9 #include <chrono>
10 
11 
12 namespace chebyshev {
13 
14  namespace benchmark {
15 
18  class timer {
19  private:
20  std::chrono::time_point<std::chrono::high_resolution_clock> s;
21 
22  public:
23 
25  timer() {
26  start();
27  }
28 
29 
31  void start() {
32  s = std::chrono::high_resolution_clock::now();
33  }
34 
35 
38  inline long double get() const {
39 
40  auto start = std::chrono::time_point_cast<std::chrono::milliseconds>(s)
41  .time_since_epoch();
42 
43  auto end = std::chrono::time_point_cast<std::chrono::milliseconds>(
44  std::chrono::high_resolution_clock::now())
45  .time_since_epoch();
46 
47  return (long double) (end - start).count();
48  }
49 
50 
54  inline long double operator()() {
55  return get();
56  }
57 
58  };
59 
60  }
61 }
62 
63 #endif
Timer class to measure elapsed time in milliseconds.
Definition: timer.h:18
long double operator()()
Returns the elapsed time since construction or start of the timer in milliseconds.
Definition: timer.h:54
timer()
Constructs the timer storing the current time.
Definition: timer.h:25
long double get() const
Returns the elapsed time since construction or start of the timer in milliseconds.
Definition: timer.h:38
void start()
Start the timer.
Definition: timer.h:31
void benchmark(const std::string &name, Function func, const std::vector< InputType > &input, unsigned int runs=settings.defaultRuns, bool quiet=false)
Run a benchmark on a generic function, with the given input vector.
Definition: benchmark.h:187
General namespace of the framework.
Definition: benchmark_structures.h:16