GCC Code Coverage Report


Directory: ../
File: src/util/Timer.h
Date: 2025-08-26 18:26:32
Exec Total Coverage
Lines: 16 16 100.0%
Functions: 6 6 100.0%
Branches: 7 10 70.0%

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 12128 explicit Timer(uint64_t *const timerOutput = nullptr) : timerOutput(timerOutput) {}
13
14 // Public methods
15 12126 void start() {
16
2/2
✓ Branch 0 (2→3) taken 11524 times.
✓ Branch 1 (2→4) taken 602 times.
12126 if (timerOutput)
17 11524 *timerOutput = 0;
18 12126 resume();
19 12126 }
20 11505 void stop() { pause(); }
21 13523 void resume() { timeStart = std::chrono::high_resolution_clock::now(); }
22 12872 void pause() {
23 12872 timeStop = std::chrono::high_resolution_clock::now();
24
2/2
✓ Branch 0 (3→4) taken 12680 times.
✓ Branch 1 (3→6) taken 192 times.
12872 if (timerOutput)
25 12680 *timerOutput += getDurationMilliseconds();
26 12872 }
27 12680 [[nodiscard]] uint64_t getDurationMilliseconds() const {
28
2/4
✓ Branch 0 (2→3) taken 12680 times.
✗ Branch 1 (2→9) not taken.
✓ Branch 2 (3→4) taken 12680 times.
✗ Branch 3 (3→9) not taken.
12680 const std::chrono::duration<double> duration = timeStop - timeStart;
29
1/2
✓ Branch 0 (4→5) taken 12680 times.
✗ Branch 1 (4→10) not taken.
12680 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