-
Notifications
You must be signed in to change notification settings - Fork 63
/
benchmark.cpp
90 lines (72 loc) · 2.22 KB
/
benchmark.cpp
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
* benchmark.cpp
*/
#include "benchmark.hpp"
#include "isa-support.hpp"
#include "opt-control.hpp"
#include <cassert>
using namespace std;
BenchArgs::BenchArgs(
const BenchmarkGroup* parent,
const std::string& id,
const std::string& description,
taglist_t tags,
featurelist_t features,
uint32_t ops_per_loop
) :
parent{parent},
id{id},
description{description},
tags{tags},
features{features},
ops_per_loop{ops_per_loop}
{}
arg_provider_t constant(void *value) {
return [=]{ return value; };
}
const arg_provider_t null_provider = constant(nullptr);
void printBenchName(Context& c, const std::string& name) {
c.out() << setprecision(c.getPrecision()) << fixed << setw(DESC_WIDTH) << name;
}
void printBenchName(Context& c, const Benchmark& b) {
printBenchName(c, b->getDescription());
}
void printResultLine(Context& c, const Benchmark& b, const TimingResult& result) {
std::ostream& os = c.out();
printBenchName(c, b);
printAlignedMetrics(c, result.getResults());
os << endl;
}
void printNameHeader(Context& c) {
c.out() << setw(DESC_WIDTH) << "Benchmark";
}
void printResultHeader(Context& c) {
// "Benchmark", "Cycles", "Nanos"
printNameHeader(c);
printAlignedMetrics(c, c.getTimerInfo().getMetricNames());
c.out() << endl;
}
BenchmarkBase::BenchmarkBase(BenchArgs args) : args{std::move(args)} {}
void BenchmarkBase::runAndPrint(Context& c) {
if (!supports(args.features)) {
// can't run this test on this hardware
printBenchName(c, this);
printOneMetric(c, std::string("Skipped because hardware doesn't support required features: ") +
container_to_string(args.features));
c.out() << endl;
} else {
runAndPrintInner(c);
}
}
std::string BenchmarkBase::getPath() const {
return getGroup().getId() + "/" + getId();
}
// a benchmark that immediately returns, useful as the "base" method
// to cancel out some forms of overhead
long dummy_bench(uint64_t iters, void* arg) {
// we jump through these hoops to get a function with a single ret
// instruction
long l;
opt_control::overwrite(l);
return l;
}