-
-
Notifications
You must be signed in to change notification settings - Fork 360
Expand file tree
/
Copy pathbench.cpp
More file actions
53 lines (44 loc) · 1.4 KB
/
bench.cpp
File metadata and controls
53 lines (44 loc) · 1.4 KB
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
#include "benchmark/benchmark.h"
#include "solution.h"
#include <cstdio>
#include <iostream>
// Variables for passed arguments
static std::string input, output;
static void bench1(benchmark::State &state) {
// Delete an output file for the case of possible crash
std::remove(output.data());
Grayscale image;
if (image.load(input, kMaxImageDimension)) {
decltype(Grayscale::data) result(new uint8_t[image.size]);
decltype(Grayscale::data) temp(new uint8_t[image.size]);
if (result && temp) {
for (auto _ : state) {
blur(result.get(), image.data.get(), image.width, image.height,
temp.get());
benchmark::DoNotOptimize(image);
}
std::swap(image.data, result);
image.save(output);
return;
}
}
state.SkipWithError("An IO problem");
}
// Register the function as a benchmark
BENCHMARK(bench1);
// Run the benchmark
int main(int argc, char **argv) {
constexpr int mandatoryArgumentsCount = 2;
if (argc < 1 + mandatoryArgumentsCount) {
std::cerr << "Usage: input.pgm output.pgm [--name=value...]" << std::endl;
return 1;
}
input = argv[1];
output = argv[2];
::benchmark::Initialize(&argc, argv);
if (::benchmark::ReportUnrecognizedArguments(argc - mandatoryArgumentsCount,
argv + mandatoryArgumentsCount))
return 1;
::benchmark::RunSpecifiedBenchmarks();
return 0;
}