Skip to content

Commit 38c17f3

Browse files
committed
[libc++] Add benchmarks for std::filesystem::path::lexically_relative
1 parent a708b4b commit 38c17f3

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

libcxx/test/benchmarks/filesystem.bench.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,4 +171,25 @@ BENCHMARK_CAPTURE(BM_LexicallyNormal, large_path, getRandomPaths, /*PathLen*/ 32
171171
->Range(2, 256)
172172
->Complexity();
173173

174+
template <class GenInput>
175+
void BM_LexicallyRelative(benchmark::State& st, GenInput gen, size_t PathLen) {
176+
using fs::path;
177+
auto BasePath = gen(st.range(0), PathLen);
178+
auto TargetPath = gen(st.range(0), PathLen);
179+
benchmark::DoNotOptimize(&BasePath);
180+
benchmark::DoNotOptimize(&TargetPath);
181+
while (st.KeepRunning()) {
182+
benchmark::DoNotOptimize(TargetPath.lexically_relative(BasePath));
183+
}
184+
st.SetComplexityN(st.range(0));
185+
}
186+
BENCHMARK_CAPTURE(BM_LexicallyRelative, small_path, getRandomPaths, /*PathLen*/ 5)
187+
->RangeMultiplier(2)
188+
->Range(2, 256)
189+
->Complexity();
190+
BENCHMARK_CAPTURE(BM_LexicallyRelative, large_path, getRandomPaths, /*PathLen*/ 32)
191+
->RangeMultiplier(2)
192+
->Range(2, 256)
193+
->Complexity();
194+
174195
BENCHMARK_MAIN();

0 commit comments

Comments
 (0)