-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbench_filesystem.cpp
62 lines (44 loc) · 1.44 KB
/
bench_filesystem.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
#include <benchmark/benchmark.h>
#include <array>
#include <string_view>
#include <vector>
#include <boost/filesystem.hpp>
namespace fs = boost::filesystem;
const std::vector<fs::path>& approvedFoldersMeyers() {
static const std::vector<fs::path> result{
// fs::path{"docs"}, fs::path{"resources"}, fs::path{"tests"}
"docs", "resources", "tests"
};
return result;
}
static constexpr std::array<std::string_view, 3> approvedFolders
//static constexpr const char* const approvedFolders[] =
{{
"docs", "resources", "tests"
}};
static void BM_Static(benchmark::State& state) {
fs::path srcDir = fs::canonical(".");
for (auto _ : state) {
for (int64_t i = 0; i < state.range(0); ++i) {
for(const auto& approvedPath : approvedFoldersMeyers()) {
fs::path p = srcDir / approvedPath;
benchmark::DoNotOptimize(p);
}
}
}
state.SetComplexityN(state.range(0));
}
static void BM_ConstExpr(benchmark::State& state) {
fs::path srcDir = fs::canonical(".");
for (auto _ : state) {
for (int64_t i = 0; i < state.range(0); ++i) {
for(const auto& approvedStrView : approvedFolders) {
fs::path p = srcDir / fs::path{std::string(approvedStrView)};
benchmark::DoNotOptimize(p);
}
}
}
state.SetComplexityN(state.range(0));
}
BENCHMARK(BM_Static)->RangeMultiplier(4)->Range(8, 8 << 16)->Complexity();
BENCHMARK(BM_ConstExpr)->RangeMultiplier(4)->Range(8, 8 << 16)->Complexity();