-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
bench.cpp
38 lines (31 loc) · 1012 Bytes
/
bench.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
#include "benchmark/benchmark.h"
#include "wordcount.hpp"
#include <iostream>
static std::string inputsDirPath;
static void bench1(benchmark::State &state) {
// Init benchmark data
// auto arg = ...;
init(/*arg*/);
// Run the benchmark
for (auto _ : state) {
auto output = wordcount(inputsDirPath);
benchmark::DoNotOptimize(output);
}
}
// Register the function as a benchmark and measure time in microseconds
BENCHMARK(bench1)->Unit(benchmark::kSecond);
// Run the benchmark
int main(int argc, char **argv) {
constexpr int mandatoryArgumentsCount = 1;
if (argc < 1 + mandatoryArgumentsCount) {
std::cerr << "Usage: lab path/to/inputs [gbench args]" << std::endl;
return 1;
}
inputsDirPath = argv[1];
::benchmark::Initialize(&argc, argv);
if (::benchmark::ReportUnrecognizedArguments(argc - mandatoryArgumentsCount,
argv + mandatoryArgumentsCount))
return 1;
::benchmark::RunSpecifiedBenchmarks();
return 0;
}