forked from mapbox/geojson-vt-cpp
-
Notifications
You must be signed in to change notification settings - Fork 1
/
util.hpp
33 lines (30 loc) · 911 Bytes
/
util.hpp
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
#pragma once
#include <chrono>
#include <fstream>
#include <iostream>
#include <sstream>
#include <stdexcept>
#include <string>
std::string loadFile(const std::string& filename) {
std::ifstream in(filename, std::ios::in | std::ios::binary);
if (in) {
std::ostringstream contents;
contents << in.rdbuf();
in.close();
return contents.str();
}
throw std::runtime_error("Error opening file");
}
class Timer {
public:
std::chrono::high_resolution_clock::time_point started;
Timer() {
started = std::chrono::high_resolution_clock::now();
}
void operator()(std::string msg) {
const auto now = std::chrono::high_resolution_clock::now();
const auto ms = std::chrono::duration_cast<std::chrono::microseconds>(now - started);
std::cerr << msg << ": " << double(ms.count()) / 1000 << "ms\n";
started = now;
}
};