GCC Code Coverage Report


Directory: ../
File: src/util/Timer.h
Date: 2025-10-27 22:48:14
Coverage Exec Excl Total
Lines: 100.0% 16 0 16
Functions: 100.0% 6 0 6
Branches: 70.0% 7 0 10

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 13948 explicit Timer(uint64_t *const timerOutput = nullptr) : timerOutput(timerOutput) {}
13
14 // Public methods
15 13946 void start() {
16
2/2
✓ Branch 2 → 3 taken 13329 times.
✓ Branch 2 → 4 taken 617 times.
13946 if (timerOutput)
17 13329 *timerOutput = 0;
18 13946 resume();
19 13946 }
20 13314 void stop() { pause(); }
21 15468 void resume() { timeStart = std::chrono::high_resolution_clock::now(); }
22 14807 void pause() {
23 14807 timeStop = std::chrono::high_resolution_clock::now();
24
2/2
✓ Branch 3 → 4 taken 14610 times.
✓ Branch 3 → 6 taken 197 times.
14807 if (timerOutput)
25 14610 *timerOutput += getDurationMilliseconds();
26 14807 }
27 14610 [[nodiscard]] uint64_t getDurationMilliseconds() const {
28
2/4
✓ Branch 2 → 3 taken 14610 times.
✗ Branch 2 → 9 not taken.
✓ Branch 3 → 4 taken 14610 times.
✗ Branch 3 → 9 not taken.
14610 const std::chrono::duration<double> duration = timeStop - timeStart;
29
1/2
✓ Branch 4 → 5 taken 14610 times.
✗ Branch 4 → 10 not taken.
14610 return std::chrono::duration_cast<std::chrono::milliseconds>(duration).count();
30 }
31
32 private:
33 uint64_t *const timerOutput;
34 std::chrono::time_point<std::chrono::system_clock> timeStart;
35 std::chrono::time_point<std::chrono::system_clock> timeStop;
36 };
37
38 } // namespace spice::compiler
39