GCC Code Coverage Report


Directory: ../
File: src/util/Timer.h
Date: 2025-12-19 06:54:40
Coverage Exec Excl Total
Lines: 100.0% 16 0 16
Functions: 100.0% 6 0 6
Branches: 75.0% 6 0 8

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 14878 explicit Timer(uint64_t *const timerOutput = nullptr) : timerOutput(timerOutput) {}
13
14 // Public methods
15 14876 void start() {
16
2/2
✓ Branch 2 → 3 taken 14236 times.
✓ Branch 2 → 4 taken 640 times.
14876 if (timerOutput)
17 14236 *timerOutput = 0;
18 14876 resume();
19 14876 }
20
21 14224 void stop() { pause(); }
22
23 16505 void resume() { timeStart = std::chrono::high_resolution_clock::now(); }
24
25 15822 void pause() {
26 15822 timeStop = std::chrono::high_resolution_clock::now();
27
2/2
✓ Branch 3 → 4 taken 15620 times.
✓ Branch 3 → 6 taken 202 times.
15822 if (timerOutput)
28 15620 *timerOutput += getDurationMilliseconds();
29 15822 }
30
31 15620 [[nodiscard]] uint64_t getDurationMilliseconds() const {
32
1/2
✓ Branch 2 → 3 taken 15620 times.
✗ Branch 2 → 9 not taken.
15620 const auto duration = timeStop - timeStart;
33
1/2
✓ Branch 3 → 4 taken 15620 times.
✗ Branch 3 → 8 not taken.
15620 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