-
Notifications
You must be signed in to change notification settings - Fork 9
/
benchmark.cpp
119 lines (102 loc) · 2.98 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#include <cassert>
#include <iostream>
#include "benchmark.h"
std::vector<std::pair<std::string,Benchmark> > DISPLAY_BENCHMARKS;
int Benchmark::next_benchmark_position = 0;
int FIND_BENCHMARK(const std::string& s) {
for (std::size_t i = 0; i < DISPLAY_BENCHMARKS.size(); i++) {
if (DISPLAY_BENCHMARKS[i].first == s) return i;
}
return -1;
}
Benchmark::Benchmark(const std::string& s) {
assert (FIND_BENCHMARK(s) == -1);
assert (s == "extracredit" ||
s == "perfect" ||
s == "average" ||
s == "stddev" ||
s == "lowest_a-" ||
s == "lowest_b-" ||
s == "lowest_c-" ||
s == "lowest_d" ||
s == "failing");
name = s;
visible = false;
percentage = -1;
color = "ffffff";
position = -1;
DISPLAY_BENCHMARKS.push_back(std::make_pair(s,*this));
}
Benchmark& Benchmark::GetBenchmark(const std::string& s) {
assert (s == "extracredit" ||
s == "perfect" ||
s == "average" ||
s == "stddev" ||
s == "lowest_a-" ||
s == "lowest_b-" ||
s == "lowest_c-" ||
s == "lowest_d" ||
s == "failing");
int i = FIND_BENCHMARK(s);
if (i == -1) {
Benchmark b(s);
i = FIND_BENCHMARK(s);
}
assert (i != -1);
return DISPLAY_BENCHMARKS[i].second;
}
void DisplayBenchmark(const std::string& s) {
Benchmark& b = Benchmark::GetBenchmark(s);
b.visible=true;
b.position = Benchmark::next_benchmark_position;
Benchmark::next_benchmark_position++;
}
int NumVisibleBenchmarks() {
return Benchmark::next_benchmark_position;
}
int WhichVisibleBenchmark(const std::string& s) {
for (std::size_t i = 0; i < DISPLAY_BENCHMARKS.size(); i++) {
if (DISPLAY_BENCHMARKS[i].first == s) { return DISPLAY_BENCHMARKS[i].second.position; }
}
return -1;
}
void SetBenchmarkPercentage(const std::string& s, float v) {
assert (s == "lowest_a-" ||
s == "lowest_b-" ||
s == "lowest_c-" ||
s == "lowest_d");
Benchmark& b = Benchmark::GetBenchmark(s);
assert (v >= 0.0 && v <= 1.0);
b.percentage = v;
}
float GetBenchmarkPercentage(const std::string& s) {
assert (s == "lowest_a-" ||
s == "lowest_b-" ||
s == "lowest_c-" ||
s == "lowest_d");
Benchmark& b = Benchmark::GetBenchmark(s);
return b.percentage;
}
void SetBenchmarkColor(const std::string& s, const std::string& c) {
assert (s == "extracredit" ||
s == "perfect" ||
s == "lowest_a-" ||
s == "lowest_b-" ||
s == "lowest_c-" ||
s == "lowest_d" ||
s == "failing");
Benchmark& b = Benchmark::GetBenchmark(s);
assert (c.size() == 6);
b.color = c;
}
const std::string& GetBenchmarkColor(const std::string& s) {
assert (s == "extracredit" ||
s == "perfect" ||
s == "lowest_a-" ||
s == "lowest_b-" ||
s == "lowest_c-" ||
s == "lowest_d" ||
s == "failing");
Benchmark& b = Benchmark::GetBenchmark(s);
return b.color;
}