Chebyshev
Unit testing for scientific software
Loading...
Searching...
No Matches
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
12namespace 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
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
General namespace of the framework.
Definition benchmark.h:22
constexpr FloatType get_nan()
Get a quiet NaN of the specified floating point type.
Definition common.h:65