GCC Code Coverage Report


Directory: ../
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 100.0% 16 / 0 / 16
Functions: 100.0% 6 / 0 / 6
Branches: 75.0% 6 / 0 / 8

src/util/Timer.h
Line Branch Exec Source
1 // Copyright (c) 2021-2026 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 31692 explicit Timer(uint64_t *const timerOutput = nullptr) : timerOutput(timerOutput) {}
13
14 // Public methods
15 31690 void start() {
16
2/2
✓ Branch 2 → 3 taken 30831 times.
✓ Branch 2 → 4 taken 859 times.
31690 if (timerOutput)
17 30831 *timerOutput = 0;
18 31690 resume();
19 31690 }
20
21 30909 void stop() { pause(); }
22
23 35175 void resume() { timeStart = std::chrono::high_resolution_clock::now(); }
24
25 34362 void pause() {
26 34362 timeStop = std::chrono::high_resolution_clock::now();
27
2/2
✓ Branch 3 → 4 taken 34054 times.
✓ Branch 3 → 6 taken 308 times.
34362 if (timerOutput)
28 34054 *timerOutput += getDurationMilliseconds();
29 34362 }
30
31 34054 [[nodiscard]] uint64_t getDurationMilliseconds() const {
32
1/2
✓ Branch 2 → 3 taken 34054 times.
✗ Branch 2 → 8 not taken.
34054 const auto duration = timeStop - timeStart;
33
1/2
✓ Branch 3 → 4 taken 34054 times.
✗ Branch 3 → 7 not taken.
34054 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