1 #include "benchmark/benchmark.h"
2 #include "GenerateInput.h"
3 #include "test_iterators.h"
4 #include "filesystem_include.h"
6 static const size_t TestNumInputs
= 1024;
9 template <class GenInputs
>
10 void BM_PathConstructString(benchmark::State
&st
, GenInputs gen
) {
12 const auto in
= gen(st
.range(0));
16 benchmark::DoNotOptimize(PP
.native().data());
17 while (st
.KeepRunning()) {
18 const path
P(PP
.native());
19 benchmark::DoNotOptimize(P
.native().data());
21 st
.SetComplexityN(st
.range(0));
23 BENCHMARK_CAPTURE(BM_PathConstructString
, large_string
,
24 getRandomStringInputs
)->Range(8, TestNumInputs
)->Complexity();
27 template <class GenInputs
>
28 void BM_PathConstructCStr(benchmark::State
&st
, GenInputs gen
) {
30 const auto in
= gen(st
.range(0));
34 benchmark::DoNotOptimize(PP
.native().data());
35 while (st
.KeepRunning()) {
36 const path
P(PP
.native().c_str());
37 benchmark::DoNotOptimize(P
.native().data());
40 BENCHMARK_CAPTURE(BM_PathConstructCStr
, large_string
,
41 getRandomStringInputs
)->Arg(TestNumInputs
);
44 template <template <class...> class ItType
, class GenInputs
>
45 void BM_PathConstructIter(benchmark::State
&st
, GenInputs gen
) {
47 using Iter
= ItType
<std::string::const_iterator
>;
48 const auto in
= gen(st
.range(0));
52 auto Start
= Iter(PP
.native().begin());
53 auto End
= Iter(PP
.native().end());
54 benchmark::DoNotOptimize(PP
.native().data());
55 benchmark::DoNotOptimize(Start
);
56 benchmark::DoNotOptimize(End
);
57 while (st
.KeepRunning()) {
58 const path
P(Start
, End
);
59 benchmark::DoNotOptimize(P
.native().data());
61 st
.SetComplexityN(st
.range(0));
63 template <class GenInputs
>
64 void BM_PathConstructInputIter(benchmark::State
&st
, GenInputs gen
) {
65 BM_PathConstructIter
<cpp17_input_iterator
>(st
, gen
);
67 template <class GenInputs
>
68 void BM_PathConstructForwardIter(benchmark::State
&st
, GenInputs gen
) {
69 BM_PathConstructIter
<forward_iterator
>(st
, gen
);
71 BENCHMARK_CAPTURE(BM_PathConstructInputIter
, large_string
,
72 getRandomStringInputs
)->Range(8, TestNumInputs
)->Complexity();
73 BENCHMARK_CAPTURE(BM_PathConstructForwardIter
, large_string
,
74 getRandomStringInputs
)->Range(8, TestNumInputs
)->Complexity();
77 template <class GenInputs
>
78 void BM_PathIterateMultipleTimes(benchmark::State
&st
, GenInputs gen
) {
80 const auto in
= gen(st
.range(0));
84 benchmark::DoNotOptimize(PP
.native().data());
85 while (st
.KeepRunning()) {
86 for (auto const& E
: PP
) {
87 benchmark::DoNotOptimize(E
.native().data());
89 benchmark::ClobberMemory();
91 st
.SetComplexityN(st
.range(0));
93 BENCHMARK_CAPTURE(BM_PathIterateMultipleTimes
, iterate_elements
,
94 getRandomStringInputs
)->Range(8, TestNumInputs
)->Complexity();
97 template <class GenInputs
>
98 void BM_PathIterateOnce(benchmark::State
&st
, GenInputs gen
) {
100 const auto in
= gen(st
.range(0));
102 for (auto& Part
: in
)
104 benchmark::DoNotOptimize(PP
.native().data());
105 while (st
.KeepRunning()) {
106 const path P
= PP
.native();
107 for (auto const& E
: P
) {
108 benchmark::DoNotOptimize(E
.native().data());
110 benchmark::ClobberMemory();
112 st
.SetComplexityN(st
.range(0));
114 BENCHMARK_CAPTURE(BM_PathIterateOnce
, iterate_elements
,
115 getRandomStringInputs
)->Range(8, TestNumInputs
)->Complexity();
117 template <class GenInputs
>
118 void BM_PathIterateOnceBackwards(benchmark::State
&st
, GenInputs gen
) {
120 const auto in
= gen(st
.range(0));
122 for (auto& Part
: in
)
124 benchmark::DoNotOptimize(PP
.native().data());
125 while (st
.KeepRunning()) {
126 const path P
= PP
.native();
127 const auto B
= P
.begin();
131 benchmark::DoNotOptimize(*I
);
133 benchmark::DoNotOptimize(*I
);
136 BENCHMARK_CAPTURE(BM_PathIterateOnceBackwards
, iterate_elements
,
137 getRandomStringInputs
)->Arg(TestNumInputs
);
139 static fs::path
getRandomPaths(int NumParts
, int PathLen
) {
142 std::string Part
= getRandomString(PathLen
);
148 template <class GenInput
>
149 void BM_LexicallyNormal(benchmark::State
&st
, GenInput gen
, size_t PathLen
) {
151 auto In
= gen(st
.range(0), PathLen
);
152 benchmark::DoNotOptimize(&In
);
153 while (st
.KeepRunning()) {
154 benchmark::DoNotOptimize(In
.lexically_normal());
156 st
.SetComplexityN(st
.range(0));
158 BENCHMARK_CAPTURE(BM_LexicallyNormal
, small_path
,
159 getRandomPaths
, /*PathLen*/5)->RangeMultiplier(2)->Range(2, 256)->Complexity();
160 BENCHMARK_CAPTURE(BM_LexicallyNormal
, large_path
,
161 getRandomPaths
, /*PathLen*/32)->RangeMultiplier(2)->Range(2, 256)->Complexity();