Kùzu C++ API
Loading...
Searching...
No Matches
timer.h
Go to the documentation of this file.
1#pragma once
2
3#include <chrono>
4#include <string>
5
6#include "assert.h"
7#include "exception.h"
8
9namespace kuzu {
10namespace common {
11
12class Timer {
13
14public:
15 void start() {
16 finished = false;
17 startTime = std::chrono::high_resolution_clock::now();
18 }
19
20 void stop() {
21 stopTime = std::chrono::high_resolution_clock::now();
22 finished = true;
23 }
24
25 double getDuration() const {
26 if (finished) {
27 auto duration = stopTime - startTime;
28 return (double)std::chrono::duration_cast<std::chrono::microseconds>(duration).count();
29 }
30 throw Exception("Timer is still running.");
31 }
32
33 uint64_t getElapsedTimeInMS() const {
34 auto now = std::chrono::high_resolution_clock::now();
35 auto duration = now - startTime;
36 auto count = std::chrono::duration_cast<std::chrono::milliseconds>(duration).count();
37 KU_ASSERT(count >= 0);
38 return count;
39 }
40
41private:
42 std::chrono::time_point<std::chrono::high_resolution_clock> startTime;
43 std::chrono::time_point<std::chrono::high_resolution_clock> stopTime;
44 bool finished = false;
45};
46
47} // namespace common
48} // namespace kuzu
#define KU_ASSERT(condition)
Definition assert.h:19
Definition exception.h:11
Definition timer.h:12
void start()
Definition timer.h:15
uint64_t getElapsedTimeInMS() const
Definition timer.h:33
double getDuration() const
Definition timer.h:25
void stop()
Definition timer.h:20
Definition array_utils.h:7