GCC Code Coverage Report


Directory: ../
File: src/util/Timer.h
Date: 2025-06-14 23:29:02
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 12120 explicit Timer(uint64_t *const timerOutput = nullptr) : timerOutput(timerOutput) {}
13
14 // Public methods
15 12118 void start() {
16
2/2
✓ Branch 0 (2→3) taken 11516 times.
✓ Branch 1 (2→4) taken 602 times.
12118 if (timerOutput)
17 11516 *timerOutput = 0;
18 12118 resume();
19 12118 }
20 11497 void stop() { pause(); }
21 13503 void resume() { timeStart = std::chrono::high_resolution_clock::now(); }
22 12852 void pause() {
23 12852 timeStop = std::chrono::high_resolution_clock::now();
24
2/2
✓ Branch 0 (3→4) taken 12660 times.
✓ Branch 1 (3→6) taken 192 times.
12852 if (timerOutput)
25 12660 *timerOutput += getDurationMilliseconds();
26 12852 }
27 12660 [[nodiscard]] uint64_t getDurationMilliseconds() const {
28
2/4
✓ Branch 0 (2→3) taken 12660 times.
✗ Branch 1 (2→9) not taken.
✓ Branch 2 (3→4) taken 12660 times.
✗ Branch 3 (3→9) not taken.
12660 const std::chrono::duration<double> duration = timeStop - timeStart;
29
1/2
✓ Branch 0 (4→5) taken 12660 times.
✗ Branch 1 (4→10) not taken.
12660 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