aboutsummaryrefslogtreecommitdiffstats
path: root/benchmark/bench_hilbert.cpp
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2022-09-16 21:19:57 -0400
committerDavid Robillard <d@drobilla.net>2022-09-16 22:31:06 -0400
commit2e4d666eec1a372d4b64c527d6c4945ad98d2b58 (patch)
treea3a61d346c3d4e5b590b08db446d17307df0e3c5 /benchmark/bench_hilbert.cpp
parentbf05ef949750cfca6e001b0f767cd2173441fc8c (diff)
downloadchilbert-2e4d666eec1a372d4b64c527d6c4945ad98d2b58.tar.gz
chilbert-2e4d666eec1a372d4b64c527d6c4945ad98d2b58.tar.bz2
chilbert-2e4d666eec1a372d4b64c527d6c4945ad98d2b58.zip
Update clang-format configuration
Diffstat (limited to 'benchmark/bench_hilbert.cpp')
-rw-r--r--benchmark/bench_hilbert.cpp93
1 files changed, 44 insertions, 49 deletions
diff --git a/benchmark/bench_hilbert.cpp b/benchmark/bench_hilbert.cpp
index 52c12dc..5793d29 100644
--- a/benchmark/bench_hilbert.cpp
+++ b/benchmark/bench_hilbert.cpp
@@ -29,85 +29,80 @@
#include <fstream>
#include <string>
-template <class H, size_t M, size_t D>
-struct BenchCoordsToIndex
-{
- Duration operator()(Context& ctx)
- {
- const auto p = make_random_point<M, D>(ctx);
- H ha = make_zero_bitvec<H, D * M>();
-
- return run_bench([&](auto) { chilbert::coords_to_index(p, M, D, ha); });
- }
+template<class H, size_t M, size_t D>
+struct BenchCoordsToIndex {
+ Duration operator()(Context& ctx)
+ {
+ const auto p = make_random_point<M, D>(ctx);
+ H ha = make_zero_bitvec<H, D * M>();
+
+ return run_bench([&](auto) { chilbert::coords_to_index(p, M, D, ha); });
+ }
};
-template <class H, size_t M, size_t D>
-struct BenchIndexToCoords
-{
- Duration operator()(Context& ctx)
- {
- auto p = make_random_point<M, D>(ctx);
- const H ha = make_random_bitvec<H, D * M>(ctx);
+template<class H, size_t M, size_t D>
+struct BenchIndexToCoords {
+ Duration operator()(Context& ctx)
+ {
+ auto p = make_random_point<M, D>(ctx);
+ const H ha = make_random_bitvec<H, D * M>(ctx);
- return run_bench([&](auto) { chilbert::index_to_coords(p, M, D, ha); });
- }
+ return run_bench([&](auto) { chilbert::index_to_coords(p, M, D, ha); });
+ }
};
/// Run benchmark for size N
-template <template <class H, size_t M, size_t D> class Bench,
- size_t M,
- size_t D>
+template<template<class H, size_t M, size_t D> class Bench, size_t M, size_t D>
void
bench_row(Context& ctx, std::ostream& os)
{
- std::array<Duration, 4> results = {
- ((M * D <= chilbert::SmallBitVec::bits_per_rack)
- ? Bench<chilbert::SmallBitVec, M, D>{}(ctx)
- : Duration{}),
- Bench<chilbert::StaticBitVec<M * D>, M, D>{}(ctx),
- Bench<chilbert::BoundedBitVec<M * D>, M, D>{}(ctx),
- Bench<chilbert::DynamicBitVec, M, D>{}(ctx),
- };
-
- write_row(os, D, results);
+ std::array<Duration, 4> results = {
+ ((M * D <= chilbert::SmallBitVec::bits_per_rack)
+ ? Bench<chilbert::SmallBitVec, M, D>{}(ctx)
+ : Duration{}),
+ Bench<chilbert::StaticBitVec<M * D>, M, D>{}(ctx),
+ Bench<chilbert::BoundedBitVec<M * D>, M, D>{}(ctx),
+ Bench<chilbert::DynamicBitVec, M, D>{}(ctx),
+ };
+
+ write_row(os, D, results);
}
/// Terminate recursion
-template <template <class H, size_t M, size_t D> class Bench, size_t M>
+template<template<class H, size_t M, size_t D> class Bench, size_t M>
void
bench_rec(Context&, std::ostream&)
-{
-}
+{}
/// Run benchmark for sizes N, Ns... (recursive helper)
-template <template <class H, size_t M, size_t D> class Bench,
- size_t M,
- size_t D,
- size_t... Ds>
+template<template<class H, size_t M, size_t D> class Bench,
+ size_t M,
+ size_t D,
+ size_t... Ds>
void
bench_rec(Context& ctx, std::ostream& os)
{
- bench_row<Bench, M, D>(ctx, os);
- bench_rec<Bench, M, Ds...>(ctx, os);
+ bench_row<Bench, M, D>(ctx, os);
+ bench_rec<Bench, M, Ds...>(ctx, os);
}
/// Run benchmark
-template <template <class H, size_t M, size_t D> class Bench>
+template<template<class H, size_t M, size_t D> 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<Bench, 8, 2, 4, 8, 16, 32, 64>(ctx, out);
+ std::ofstream out("hilbert_" + name + ".txt");
+ out << "d\tsmall\tstatic\tbounded\tdynamic\n";
+ bench_rec<Bench, 8, 2, 4, 8, 16, 32, 64>(ctx, out);
}
int
main()
{
- Context ctx;
+ Context ctx;
- bench<BenchCoordsToIndex>(ctx, "coords_to_index");
- bench<BenchIndexToCoords>(ctx, "index_to_coords");
+ bench<BenchCoordsToIndex>(ctx, "coords_to_index");
+ bench<BenchIndexToCoords>(ctx, "index_to_coords");
- return 0;
+ return 0;
}