// Copyright 2018-2022 David Robillard // SPDX-License-Identifier: GPL-2.0-or-later #include "bench_utils.hpp" #include "test_utils.hpp" #include "chilbert/BoundedBitVec.hpp" // IWYU pragma: keep #include "chilbert/DynamicBitVec.hpp" // IWYU pragma: keep #include "chilbert/SmallBitVec.hpp" #include "chilbert/StaticBitVec.hpp" // IWYU pragma: keep #include "chilbert/chilbert.hpp" #include #include #include #include template struct BenchCoordsToIndex { Duration operator()(Context& ctx) { const auto p = make_random_point(ctx); H ha = make_zero_bitvec(); return run_bench([&](auto) { chilbert::coords_to_index(p, M, D, ha); }); } }; template struct BenchIndexToCoords { Duration operator()(Context& ctx) { auto p = make_random_point(ctx); const H ha = make_random_bitvec(ctx); return run_bench([&](auto) { chilbert::index_to_coords(p, M, D, ha); }); } }; /// Run benchmark for size N template class Bench, size_t M, size_t D> void bench_row(Context& ctx, std::ostream& os) { std::array results = { ((M * D <= chilbert::SmallBitVec::bits_per_rack) ? Bench{}(ctx) : Duration{}), Bench, M, D>{}(ctx), Bench, M, D>{}(ctx), Bench{}(ctx), }; write_row(os, D, results); } /// Terminate recursion template class Bench, size_t M> void bench_rec(Context&, std::ostream&) {} /// Run benchmark for sizes N, Ns... (recursive helper) template class Bench, size_t M, size_t D, size_t... Ds> void bench_rec(Context& ctx, std::ostream& os) { bench_row(ctx, os); bench_rec(ctx, os); } /// Run benchmark template class Bench> void bench(Context& ctx, const std::string& name) { std::ofstream out("hilbert_" + name + ".txt"); out << "d\tsmall\tstatic\tbounded\tdynamic\n"; bench_rec(ctx, out); } int main() { Context ctx; bench(ctx, "coords_to_index"); bench(ctx, "index_to_coords"); return 0; }