GCC Code Coverage Report


Directory: ../
File: src/util/Timer.h
Date: 2024-11-22 23:10:59
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-2024 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 11774 explicit Timer(uint64_t *const timerOutput = nullptr) : timerOutput(timerOutput) {}
13
14 // Public methods
15 11772 void start() {
16
2/2
✓ Branch 0 taken 11204 times.
✓ Branch 1 taken 568 times.
11772 if (timerOutput)
17 11204 *timerOutput = 0;
18 11772 resume();
19 11772 }
20 11175 void stop() { pause(); }
21 15442 void resume() { timeStart = std::chrono::high_resolution_clock::now(); }
22 14815 void pause() {
23 14815 timeStop = std::chrono::high_resolution_clock::now();
24
2/2
✓ Branch 0 taken 14637 times.
✓ Branch 1 taken 178 times.
14815 if (timerOutput)
25 14637 *timerOutput += getDurationMilliseconds();
26 14815 }
27 14637 [[nodiscard]] uint64_t getDurationMilliseconds() const {
28
2/4
✓ Branch 1 taken 14637 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 14637 times.
✗ Branch 5 not taken.
14637 const std::chrono::duration<double> duration = timeStop - timeStart;
29
1/2
✓ Branch 1 taken 14637 times.
✗ Branch 2 not taken.
14637 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