Files
TheRock/compiler/amd-llvm/libcxx/test/benchmarks/filesystem.bench.cpp
T
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

189 lines
6.0 KiB
C++

//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17
#include <filesystem>
#include "GenerateInput.h"
#include "benchmark/benchmark.h"
#include "test_iterators.h"
namespace fs = std::filesystem;
static const size_t TestNumInputs = 1024;
template <class GenInputs>
void BM_PathConstructString(benchmark::State& st, GenInputs gen) {
using fs::path;
const auto in = gen(st.range(0));
path PP;
for (auto& Part : in)
PP /= Part;
benchmark::DoNotOptimize(PP.native().data());
while (st.KeepRunning()) {
const path P(PP.native());
benchmark::DoNotOptimize(P.native().data());
}
}
BENCHMARK_CAPTURE(BM_PathConstructString, large_string, getRandomStringInputs)
->Name("filesystem::path::ctor(std::string const&)")
->Range(8, TestNumInputs);
template <class GenInputs>
void BM_PathConstructCStr(benchmark::State& st, GenInputs gen) {
using fs::path;
const auto in = gen(st.range(0));
path PP;
for (auto& Part : in)
PP /= Part;
benchmark::DoNotOptimize(PP.native().data());
while (st.KeepRunning()) {
const path P(PP.native().c_str());
benchmark::DoNotOptimize(P.native().data());
}
}
BENCHMARK_CAPTURE(BM_PathConstructCStr, large_string, getRandomStringInputs)
->Name("filesystem::path::ctor(char const*)")
->Arg(TestNumInputs);
template <template <class...> class ItType, class GenInputs>
void BM_PathConstructIter(benchmark::State& st, GenInputs gen) {
using fs::path;
using Iter = ItType<std::string::const_iterator>;
const auto in = gen(st.range(0));
path PP;
for (auto& Part : in)
PP /= Part;
auto Start = Iter(PP.native().begin());
auto End = Iter(PP.native().end());
benchmark::DoNotOptimize(PP.native().data());
benchmark::DoNotOptimize(Start);
benchmark::DoNotOptimize(End);
while (st.KeepRunning()) {
const path P(Start, End);
benchmark::DoNotOptimize(P.native().data());
}
}
BENCHMARK_CAPTURE(BM_PathConstructIter<cpp17_input_iterator>, large_string, getRandomStringInputs)
->Name("filesystem::path::ctor(input-iter, input-iter)")
->Range(8, TestNumInputs);
BENCHMARK_CAPTURE(BM_PathConstructIter<forward_iterator>, large_string, getRandomStringInputs)
->Name("filesystem::path::ctor(forward-iter, forward-iter)")
->Range(8, TestNumInputs);
template <class GenInputs>
void BM_PathIterateMultipleTimes(benchmark::State& st, GenInputs gen) {
using fs::path;
const auto in = gen(st.range(0));
path PP;
for (auto& Part : in)
PP /= Part;
benchmark::DoNotOptimize(PP.native().data());
while (st.KeepRunning()) {
for (auto const& E : PP) {
benchmark::DoNotOptimize(E.native().data());
}
benchmark::ClobberMemory();
}
}
BENCHMARK_CAPTURE(BM_PathIterateMultipleTimes, iterate_elements, getRandomStringInputs)
->Name("filesystem::path::iterator (iterate multiple times)")
->Range(8, TestNumInputs);
template <class GenInputs>
void BM_PathIterateOnce(benchmark::State& st, GenInputs gen) {
using fs::path;
const auto in = gen(st.range(0));
path PP;
for (auto& Part : in)
PP /= Part;
benchmark::DoNotOptimize(PP.native().data());
while (st.KeepRunning()) {
const path P = PP.native();
for (auto const& E : P) {
benchmark::DoNotOptimize(E.native().data());
}
benchmark::ClobberMemory();
}
}
BENCHMARK_CAPTURE(BM_PathIterateOnce, iterate_elements, getRandomStringInputs)
->Name("filesystem::path::iterator (iterate once)")
->Range(8, TestNumInputs);
template <class GenInputs>
void BM_PathIterateOnceBackwards(benchmark::State& st, GenInputs gen) {
using fs::path;
const auto in = gen(st.range(0));
path PP;
for (auto& Part : in)
PP /= Part;
benchmark::DoNotOptimize(PP.native().data());
while (st.KeepRunning()) {
const path P = PP.native();
const auto B = P.begin();
auto I = P.end();
while (I != B) {
--I;
benchmark::DoNotOptimize(*I);
}
benchmark::DoNotOptimize(*I);
}
}
BENCHMARK_CAPTURE(BM_PathIterateOnceBackwards, iterate_elements, getRandomStringInputs)
->Name("filesystem::path::iterator (iterate once backwards)")
->Arg(TestNumInputs);
static fs::path getRandomPaths(int NumParts, int PathLen) {
fs::path Result;
while (NumParts--) {
std::string Part = getRandomString(PathLen);
Result /= Part;
}
return Result;
}
template <class GenInput>
void BM_LexicallyNormal(benchmark::State& st, GenInput gen, size_t PathLen) {
using fs::path;
auto In = gen(st.range(0), PathLen);
benchmark::DoNotOptimize(&In);
while (st.KeepRunning()) {
benchmark::DoNotOptimize(In.lexically_normal());
}
}
BENCHMARK_CAPTURE(BM_LexicallyNormal, small_path, getRandomPaths, /*PathLen*/ 5)
->Name("filesystem::path::lexically_normal() (small path)")
->RangeMultiplier(2)
->Range(2, 256);
BENCHMARK_CAPTURE(BM_LexicallyNormal, large_path, getRandomPaths, /*PathLen*/ 32)
->Name("filesystem::path::lexically_normal() (large path)")
->RangeMultiplier(2)
->Range(2, 256);
template <class GenInput>
void BM_LexicallyRelative(benchmark::State& st, GenInput gen, size_t PathLen) {
auto BasePath = gen(st.range(0), PathLen);
auto TargetPath = gen(st.range(0), PathLen);
benchmark::DoNotOptimize(&BasePath);
benchmark::DoNotOptimize(&TargetPath);
for (auto _ : st) {
benchmark::DoNotOptimize(TargetPath.lexically_relative(BasePath));
}
}
BENCHMARK_CAPTURE(BM_LexicallyRelative, small_path, getRandomPaths, /*PathLen*/ 5)
->Name("filesystem::path::lexically_relative() (small path)")
->RangeMultiplier(2)
->Range(2, 256);
BENCHMARK_CAPTURE(BM_LexicallyRelative, large_path, getRandomPaths, /*PathLen*/ 32)
->Name("filesystem::path::lexically_relative() (large path)")
->RangeMultiplier(2)
->Range(2, 256);
BENCHMARK_MAIN();