| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // Copyright (c) 2021-2025 ChilliBits. All rights reserved. | ||
| 2 | |||
| 3 | #pragma once | ||
| 4 | |||
| 5 | #include <chrono> | ||
| 6 | |||
| 7 | namespace spice::compiler { | ||
| 8 | |||
| 9 | class Timer { | ||
| 10 | public: | ||
| 11 | // Constructors | ||
| 12 | 14617 | explicit Timer(uint64_t *const timerOutput = nullptr) : timerOutput(timerOutput) {} | |
| 13 | |||
| 14 | // Public methods | ||
| 15 | 14615 | void start() { | |
| 16 |
2/2✓ Branch 2 → 3 taken 13991 times.
✓ Branch 2 → 4 taken 624 times.
|
14615 | if (timerOutput) |
| 17 | 13991 | *timerOutput = 0; | |
| 18 | 14615 | resume(); | |
| 19 | 14615 | } | |
| 20 | |||
| 21 | 13976 | void stop() { pause(); } | |
| 22 | |||
| 23 | 16208 | void resume() { timeStart = std::chrono::high_resolution_clock::now(); } | |
| 24 | |||
| 25 | 15540 | void pause() { | |
| 26 | 15540 | timeStop = std::chrono::high_resolution_clock::now(); | |
| 27 |
2/2✓ Branch 3 → 4 taken 15343 times.
✓ Branch 3 → 6 taken 197 times.
|
15540 | if (timerOutput) |
| 28 | 15343 | *timerOutput += getDurationMilliseconds(); | |
| 29 | 15540 | } | |
| 30 | |||
| 31 | 15343 | [[nodiscard]] uint64_t getDurationMilliseconds() const { | |
| 32 |
1/2✓ Branch 2 → 3 taken 15343 times.
✗ Branch 2 → 9 not taken.
|
15343 | const auto duration = timeStop - timeStart; |
| 33 |
1/2✓ Branch 3 → 4 taken 15343 times.
✗ Branch 3 → 8 not taken.
|
15343 | return std::chrono::duration_cast<std::chrono::milliseconds>(duration).count(); |
| 34 | } | ||
| 35 | |||
| 36 | private: | ||
| 37 | uint64_t *const timerOutput; | ||
| 38 | std::chrono::time_point<std::chrono::high_resolution_clock> timeStart; | ||
| 39 | std::chrono::time_point<std::chrono::high_resolution_clock> timeStop; | ||
| 40 | }; | ||
| 41 | |||
| 42 | } // namespace spice::compiler | ||
| 43 |