carl  24.04
Computer ARithmetic Library
Timer.h
Go to the documentation of this file.
1 /**
2  * @file Timer.h
3  * @author Sebastian Junges
4  * @author Gereon Kremer
5  *
6  */
7 
8 #pragma once
9 
10 #include <chrono>
11 #include <ostream>
12 
13 namespace carl
14 {
15 /**
16  * This classes provides an easy way to obtain the current number of milliseconds that the program has been running.
17  */
18 class Timer {
19  /// The clock type used jere.
20  using clock = std::chrono::high_resolution_clock;
21  /// The duration type used here.
22  using duration = std::chrono::duration<std::size_t,std::milli>;
23  /// Start of this timer.
25 public:
26  Timer() noexcept: mStart(clock::now()) {}
27 
28  /**
29  * Calculated the number of milliseconds since this object has been created.
30  * @return Milliseconds passed.
31  */
32  std::size_t passed() const noexcept {
34  return std::chrono::duration_cast<duration>(d).count();
35  }
36 
37  /**
38  * Reset the start point to now.
39  */
40  void reset() noexcept {
41  mStart = clock::now();
42  }
43 };
44 /**
45  * Streaming operator for a Timer.
46  * Prints the result of `t.passed()`.
47  * @param os Output stream.
48  * @param t Timer.
49  * @return os.
50  */
51 inline std::ostream& operator<<(std::ostream& os, const Timer& t) {
52  return os << t.passed();
53 }
54 
55 }
carl is the main namespace for the library.
std::ostream & operator<<(std::ostream &os, const BasicConstraint< Poly > &c)
Prints the given constraint on the given stream.
clock::time_point time_point
The type of a time point.
Definition: Timing.h:14
std::chrono::duration< std::size_t, std::milli > duration
The duration type used here.
Definition: Timing.h:12
auto now()
Return the current time point.
Definition: Timing.h:17
This classes provides an easy way to obtain the current number of milliseconds that the program has b...
Definition: Timer.h:18
void reset() noexcept
Reset the start point to now.
Definition: Timer.h:40
std::size_t passed() const noexcept
Calculated the number of milliseconds since this object has been created.
Definition: Timer.h:32
Timer() noexcept
Definition: Timer.h:26
std::chrono::high_resolution_clock clock
The clock type used jere.
Definition: Timer.h:20
std::chrono::duration< std::size_t, std::milli > duration
The duration type used here.
Definition: Timer.h:22
clock::time_point mStart
Start of this timer.
Definition: Timer.h:24