forked from preda/gpuowl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimeutil.h
37 lines (27 loc) · 776 Bytes
/
timeutil.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Copyright (C) 2017-2018 Mihai Preda.
#pragma once
#include "common.h"
#include <chrono>
#include <string>
class Timer {
using clock = std::chrono::steady_clock;
clock::time_point start;
public:
Timer() : start(clock::now()) {}
void reset() { start = clock::now(); }
double elapsedSecs() const { return std::chrono::duration<double>(clock::now() - start).count(); }
u64 deltaNanos() {
auto now = clock::now();
u64 ret = std::chrono::duration<u64, std::nano>(now - start).count();
start = now;
return ret;
}
double deltaSecs() {
auto now = clock::now();
double ret = std::chrono::duration<double>(now - start).count();
start = now;
return ret;
}
};
std::string timeStr();
std::string timeStr(const char *format);