GCC Code Coverage Report


Directory: ../
File: src/util/Timer.h
Date: 2025-02-05 01:09:36
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 11525 explicit Timer(uint64_t *const timerOutput = nullptr) : timerOutput(timerOutput) {}
13
14 // Public methods
15 11523 void start() {
16
2/2
✓ Branch 0 (2→3) taken 10935 times.
✓ Branch 1 (2→4) taken 588 times.
11523 if (timerOutput)
17 10935 *timerOutput = 0;
18 11523 resume();
19 11523 }
20 10912 void stop() { pause(); }
21 12837 void resume() { timeStart = std::chrono::high_resolution_clock::now(); }
22 12196 void pause() {
23 12196 timeStop = std::chrono::high_resolution_clock::now();
24
2/2
✓ Branch 0 (3→4) taken 12009 times.
✓ Branch 1 (3→6) taken 187 times.
12196 if (timerOutput)
25 12009 *timerOutput += getDurationMilliseconds();
26 12196 }
27 12009 [[nodiscard]] uint64_t getDurationMilliseconds() const {
28
2/4
✓ Branch 0 (2→3) taken 12009 times.
✗ Branch 1 (2→9) not taken.
✓ Branch 2 (3→4) taken 12009 times.
✗ Branch 3 (3→9) not taken.
12009 const std::chrono::duration<double> duration = timeStop - timeStart;
29
1/2
✓ Branch 0 (4→5) taken 12009 times.
✗ Branch 1 (4→10) not taken.
12009 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