netxsimdg
Loading...
Searching...
No Matches
ScopedTimer_test.cpp
Go to the documentation of this file.
1
9
10#include "include/Timer.hpp"
11
12#include <chrono>
13#include <iostream>
14#include <thread>
15
16#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
17#include <doctest/doctest.h>
18
19namespace Nextsim {
20
21void timeAndSleep()
22{
23 ScopedTimer tas("time and sleep");
24 std::this_thread::sleep_for(std::chrono::milliseconds(45));
25}
26
27TEST_SUITE_BEGIN("ScopedTimer");
28TEST_CASE("Test the scope dependent timer")
29{
32
33 ScopedTimer testScopeTimer("test scope timer");
34 {
35 ScopedTimer localScopeTimer("local scope timer");
36 timeAndSleep();
37 localScopeTimer.substitute("second scope timer");
38 std::this_thread::sleep_for(std::chrono::milliseconds(35));
39 }
40 timeAndSleep();
41
42 const int nint = 10;
43 for (int i = 0; i < nint; ++i) {
44 ScopedTimer loop("loop timer");
45 std::this_thread::sleep_for(std::chrono::milliseconds(5));
46 }
47
48 for (int i = 0; i < nint; ++i) {
49 ScopedTimer loop("loop timer 2");
50 timeAndSleep();
51 }
52
53 testScopeTimer.substitute("replacement timer");
54 std::this_thread::sleep_for(std::chrono::milliseconds(1));
55
56 std::cout << ScopedTimer::timer() << std::endl;
57}
58TEST_SUITE_END();
59
60} /* namespace Nextsim */
static Timer & timer()
Returns a reference to the underlying Timer.
static void setTimerAddress(Timer *timer)
void reset()
Deletes all timers except the root, which is reset.
Definition Timer.cpp:110
static Timer main
Static timer for general use.
Definition Timer.hpp:109