-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
54 lines (44 loc) · 1.54 KB
/
main.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
#include "util.h"
#include "algos.h"
#include <atomic>
#include <chrono>
#include <cstring>
#include <type_traits>
int main(int argc, const char* *argv) {
if (argc < 2 || argc > 3) {
std::cerr << "Usage: " << argv[0] << " <input_file> [<num_runs = 1>]\n";
return 1;
}
int numRuns = 1;
if (argc > 2) {
numRuns = atoi(argv[2]);
if (numRuns == 0) {
std::cerr << "Usage: " << argv[0] << " <input_file> [<num_runs = 1>]\n";
return 1;
}
}
const auto filename = argv[1];
const auto content = loadFile(filename);
clobberMemory();
std::chrono::nanoseconds minDuration = std::chrono::nanoseconds::max();
int resultValue = 0;
for (int i = 0; i != numRuns; ++i) {
const auto start = PerfClock::now();
resultValue = algos::TEST_ALGO(content.c_str(), content.size());
const auto duration = std::chrono::nanoseconds(PerfClock::now() - start);
minDuration = std::min(minDuration, duration);
}
clobberMemory();
const auto maxSpeed = content.size() * NsPerS / minDuration.count() / Mebibyte;
std::cout <<
"{" \
"\"algo\": \"" STR(TEST_ALGO) "\", " \
"\"input_file\": \"" << filename << "\", " \
"\"input_size\": " << content.size() << ", " \
"\"num_runs\": " << numRuns << ", " \
"\"result\": " << resultValue << ", " \
"\"time_ns\": " << minDuration.count() << ", " \
"\"mib_per_s\": " << maxSpeed <<
"}\n";
return 0;
}