-
Notifications
You must be signed in to change notification settings - Fork 0
/
Help.h
38 lines (32 loc) · 898 Bytes
/
Help.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
38
#pragma once
#include <iostream>
#include <chrono>
#define DEBUG
#ifdef DEBUG
#define TRACE(fmt, ...) \
printf(fmt, ##__VA_ARGS__)
#else
#define TRACE(fmt, ...)
#endif
struct BlockTimer {
std::chrono::high_resolution_clock::time_point begin;
BlockTimer() : begin(std::chrono::high_resolution_clock::now()) {}
~BlockTimer() {
double t = std::chrono::duration<double>(
std::chrono::high_resolution_clock::now() - begin)
.count();
if (t > 0) std::cout << "...took " << t << " seconds." << std::endl;
}
};
struct StopWatch {
std::chrono::high_resolution_clock::time_point begin;
void tic() {
begin = std::chrono::high_resolution_clock::now();
}
double toc() {
double t = std::chrono::duration<double>(
std::chrono::high_resolution_clock::now() - begin)
.count();
return t;
}
};