A clock for tests: wait_for advances it instead of sleeping.
More...
#include <algotradelib/src/runner/clock.hpp>
|
| | ManualClock (std::chrono::system_clock::time_point start={}) |
| | Constructs a clock.
|
| std::chrono::system_clock::time_point | now () const noexcept |
| | Returns the current time.
|
| std::chrono::steady_clock::time_point | monotonic_now () const noexcept |
| | Returns the monotonic reading: how far wait_for and advance have moved the clock.
|
| void | wait_for (std::chrono::nanoseconds duration) noexcept |
| | Advances the clock by a duration instead of waiting, and counts the wait.
|
| void | advance (std::chrono::nanoseconds duration) noexcept |
| | Advances the clock without counting a wait: time that passed, as inside a slow call.
|
| void | jump (std::chrono::nanoseconds duration) noexcept |
| | Moves the wall-clock reading alone, forward or back, as an operator or NTP setting the clock does.
|
| std::size_t | waits () const noexcept |
| | Returns how many times wait_for was called.
|
| std::chrono::nanoseconds | waited () const noexcept |
| | Returns the total positive duration passed to wait_for.
|
A clock for tests: wait_for advances it instead of sleeping.
A loop under test runs instantly while seeing whatever elapsed time the test chooses. waits() counts the waits, so a test can tell a loop that paced itself from one that spun.
Definition at line 96 of file clock.hpp.
◆ ManualClock()
| algotradelib::runner::ManualClock::ManualClock |
( |
std::chrono::system_clock::time_point | start = {} | ) |
|
|
inlineexplicit |
Constructs a clock.
- Parameters
-
Definition at line 102 of file clock.hpp.
◆ advance()
| void algotradelib::runner::ManualClock::advance |
( |
std::chrono::nanoseconds | duration | ) |
|
|
inlinenoexcept |
Advances the clock without counting a wait: time that passed, as inside a slow call.
- Parameters
-
| duration | The duration; zero or negative does nothing to the monotonic reading. |
Definition at line 133 of file clock.hpp.
◆ jump()
| void algotradelib::runner::ManualClock::jump |
( |
std::chrono::nanoseconds | duration | ) |
|
|
inlinenoexcept |
Moves the wall-clock reading alone, forward or back, as an operator or NTP setting the clock does.
- Parameters
-
Definition at line 144 of file clock.hpp.
◆ monotonic_now()
| std::chrono::steady_clock::time_point algotradelib::runner::ManualClock::monotonic_now |
( |
| ) |
const |
|
inlinenoexcept |
Returns the monotonic reading: how far wait_for and advance have moved the clock.
- Returns
- The reading; jump does not move it.
Definition at line 114 of file clock.hpp.
◆ now()
| std::chrono::system_clock::time_point algotradelib::runner::ManualClock::now |
( |
| ) |
const |
|
inlinenoexcept |
Returns the current time.
- Returns
- The time the clock has been advanced to.
Definition at line 108 of file clock.hpp.
◆ wait_for()
| void algotradelib::runner::ManualClock::wait_for |
( |
std::chrono::nanoseconds | duration | ) |
|
|
inlinenoexcept |
Advances the clock by a duration instead of waiting, and counts the wait.
- Parameters
-
| duration | The duration; zero or negative counts the wait without advancing. |
Definition at line 120 of file clock.hpp.
◆ waited()
| std::chrono::nanoseconds algotradelib::runner::ManualClock::waited |
( |
| ) |
const |
|
inlinenoexcept |
Returns the total positive duration passed to wait_for.
- Returns
- The sum.
Definition at line 158 of file clock.hpp.
◆ waits()
| std::size_t algotradelib::runner::ManualClock::waits |
( |
| ) |
const |
|
inlinenoexcept |
Returns how many times wait_for was called.
- Returns
- The count.
Definition at line 152 of file clock.hpp.
The documentation for this class was generated from the following file: