-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.h
50 lines (45 loc) · 1.25 KB
/
utils.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
39
40
41
42
43
44
45
46
47
48
49
50
#pragma once
#include <iostream>
#include <stdlib.h>
#include <chrono>
#include <map>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include "hauta.h"
#define Q(...) #__VA_ARGS__
#define QUOTE(...) Q(__VA_ARGS__)
#define SHOW_MACRO(x) #x ": " QUOTE(x)
#define SHOW_VAR(x) #x ": " << x
// simple logger
#define LOG if (rank == 0) std::cout
struct Timer {
using Clock = std::chrono::high_resolution_clock;
using Event = std::chrono::time_point<Clock>;
std::chrono::duration<double> duration;
Event _start;
void start() { _start = Clock::now(); }
void stop() { duration += Clock::now() - _start; }
double count() const { return duration.count(); }
};
using Timings = std::map<std::string, Timer>;
struct Averager {
std::vector<double> values;
void push(double flopValue) { values.push_back(flopValue); }
double count() const {
return
std::accumulate(values.begin(), values.end(), 0.0) / values.size();
}
size_t size() const { return values.size(); }
double sigma() const {
const double mu = count();
double sigma = 0.0;
for (auto x: values) {
sigma += (x - mu) * (x - mu);
}
sigma /= values.size();
return std::sqrt(sigma);
}
};
using Averages = std::map<std::string, Averager>;