From 2d882906325e9406c9419ed47e53788db845641e Mon Sep 17 00:00:00 2001 From: Jacob Lifshay Date: Tue, 26 Jul 2022 18:29:47 -0700 Subject: [PATCH] Config is getting big, pass by reference rather than value --- src/aarch64/aarch64_benchmarks.cpp | 6 ++--- src/aarch64/aarch64_benchmarks.h | 2 +- src/all_benchmarks.cpp | 4 +-- src/all_benchmarks.h | 2 +- .../c11_atomics/c11_atomics_benchmarks.cpp | 25 ++++++++++--------- .../c11_atomics/c11_atomics_benchmarks.h | 2 +- src/common/common_benchmarks.cpp | 4 +-- src/common/common_benchmarks.h | 2 +- src/harness.cpp | 4 +-- src/harness.h | 10 ++++---- src/powerpc64le/powerpc64le_benchmarks.cpp | 6 ++--- src/powerpc64le/powerpc64le_benchmarks.h | 2 +- src/x86_64/x86_64_benchmarks.cpp | 6 ++--- src/x86_64/x86_64_benchmarks.h | 2 +- 14 files changed, 39 insertions(+), 38 deletions(-) diff --git a/src/aarch64/aarch64_benchmarks.cpp b/src/aarch64/aarch64_benchmarks.cpp index 81f729c..2e39a35 100644 --- a/src/aarch64/aarch64_benchmarks.cpp +++ b/src/aarch64/aarch64_benchmarks.cpp @@ -2,7 +2,7 @@ #ifdef __aarch64__ -std::vector aarch64_benchmarks(Config config) +std::vector aarch64_benchmarks(const Config &config) { std::vector retval; // TODO: add aarch64 benchmarks @@ -12,9 +12,9 @@ std::vector aarch64_benchmarks(Config config) #else -std::vector aarch64_benchmarks(Config) +std::vector aarch64_benchmarks(const Config &) { return {}; } -#endif \ No newline at end of file +#endif diff --git a/src/aarch64/aarch64_benchmarks.h b/src/aarch64/aarch64_benchmarks.h index b79cc9f..47a751c 100644 --- a/src/aarch64/aarch64_benchmarks.h +++ b/src/aarch64/aarch64_benchmarks.h @@ -2,4 +2,4 @@ #include "../harness.h" -std::vector aarch64_benchmarks(Config config); \ No newline at end of file +std::vector aarch64_benchmarks(const Config &config); diff --git a/src/all_benchmarks.cpp b/src/all_benchmarks.cpp index 748541c..e136c4a 100644 --- a/src/all_benchmarks.cpp +++ b/src/all_benchmarks.cpp @@ -6,7 +6,7 @@ #include #include -std::vector all_benchmarks(Config config) +std::vector all_benchmarks(const Config &config) { std::vector retval = common_benchmarks(config); { @@ -25,4 +25,4 @@ std::vector all_benchmarks(Config config) std::back_inserter(retval)); } return retval; -} \ No newline at end of file +} diff --git a/src/all_benchmarks.h b/src/all_benchmarks.h index 9447131..b759cf6 100644 --- a/src/all_benchmarks.h +++ b/src/all_benchmarks.h @@ -2,4 +2,4 @@ #include "harness.h" -std::vector all_benchmarks(Config config); \ No newline at end of file +std::vector all_benchmarks(const Config &config); diff --git a/src/common/c11_atomics/c11_atomics_benchmarks.cpp b/src/common/c11_atomics/c11_atomics_benchmarks.cpp index 01f831c..20d02b0 100644 --- a/src/common/c11_atomics/c11_atomics_benchmarks.cpp +++ b/src/common/c11_atomics/c11_atomics_benchmarks.cpp @@ -47,8 +47,9 @@ MEMORY_ORDER_NAME(seq_cst) template using Buf = std::shared_ptr>>; template -static void push_atomic_bench(std::vector &benches, Config config, - Buf buf, Fn fn, NameParts &&...name_parts) +static void push_atomic_bench(std::vector &benches, + const Config &config, Buf buf, Fn fn, + NameParts &&...name_parts) { auto log2_stride = config.log2_stride; std::size_t index_mask = 1; @@ -71,8 +72,8 @@ static void push_atomic_bench(std::vector &benches, Config config, } template -static void rmw_benchmarks(std::vector &benches, Config config, - Buf buf) +static void rmw_benchmarks(std::vector &benches, + const Config &config, Buf buf) { push_atomic_bench( benches, config, buf, @@ -113,8 +114,8 @@ static void rmw_benchmarks(std::vector &benches, Config config, } template -static void load_benchmarks(std::vector &benches, Config config, - Buf buf) +static void load_benchmarks(std::vector &benches, + const Config &config, Buf buf) { push_atomic_bench( benches, config, buf, @@ -125,8 +126,8 @@ static void load_benchmarks(std::vector &benches, Config config, } template -static void store_benchmarks(std::vector &benches, Config config, - Buf buf) +static void store_benchmarks(std::vector &benches, + const Config &config, Buf buf) { push_atomic_bench( benches, config, buf, @@ -137,8 +138,8 @@ static void store_benchmarks(std::vector &benches, Config config, } template -static void cmp_xchg_benchmarks(std::vector &benches, Config config, - Buf buf) +static void cmp_xchg_benchmarks(std::vector &benches, + const Config &config, Buf buf) { push_atomic_bench( benches, config, buf, @@ -163,7 +164,7 @@ static void cmp_xchg_benchmarks(std::vector &benches, Config config, } template -static void benchmarks(std::vector &benches, Config config) +static void benchmarks(std::vector &benches, const Config &config) { std::size_t buf_size = 1; buf_size <<= config.log2_memory_location_count; @@ -208,7 +209,7 @@ static void benchmarks(std::vector &benches, Config config) std::memory_order_seq_cst>(benches, config, buf); } -std::vector c11_atomics_benchmarks(Config config) +std::vector c11_atomics_benchmarks(const Config &config) { std::vector benches; benchmarks(benches, config); diff --git a/src/common/c11_atomics/c11_atomics_benchmarks.h b/src/common/c11_atomics/c11_atomics_benchmarks.h index 9966297..27baed9 100644 --- a/src/common/c11_atomics/c11_atomics_benchmarks.h +++ b/src/common/c11_atomics/c11_atomics_benchmarks.h @@ -2,4 +2,4 @@ #include "../../harness.h" -std::vector c11_atomics_benchmarks(Config config); \ No newline at end of file +std::vector c11_atomics_benchmarks(const Config &config); diff --git a/src/common/common_benchmarks.cpp b/src/common/common_benchmarks.cpp index 42007a4..3179ec7 100644 --- a/src/common/common_benchmarks.cpp +++ b/src/common/common_benchmarks.cpp @@ -1,8 +1,8 @@ #include "common_benchmarks.h" #include "c11_atomics/c11_atomics_benchmarks.h" -std::vector common_benchmarks(Config config) +std::vector common_benchmarks(const Config &config) { auto retval = c11_atomics_benchmarks(config); return retval; -} \ No newline at end of file +} diff --git a/src/common/common_benchmarks.h b/src/common/common_benchmarks.h index 9505408..e3c24b1 100644 --- a/src/common/common_benchmarks.h +++ b/src/common/common_benchmarks.h @@ -2,4 +2,4 @@ #include "../harness.h" -std::vector common_benchmarks(Config config); \ No newline at end of file +std::vector common_benchmarks(const Config &config); diff --git a/src/harness.cpp b/src/harness.cpp index affe919..e28eac9 100644 --- a/src/harness.cpp +++ b/src/harness.cpp @@ -172,7 +172,7 @@ struct WriteDuration final }; void BenchHarnessBase::base_run( - Config config, + const Config &config, void (*fn)(BenchHarnessBase *bench_harness_base, std::uint64_t iteration_count, std::uint32_t thread_num)) { @@ -259,4 +259,4 @@ void BenchHarnessBase::base_run( std::shared_ptr BenchHarnessBase::get_thread_cache() { return ThreadCache::get(); -} \ No newline at end of file +} diff --git a/src/harness.h b/src/harness.h index f623114..72ee8d1 100644 --- a/src/harness.h +++ b/src/harness.h @@ -30,7 +30,7 @@ class BenchHarnessBase std::shared_ptr thread_cache; class ThreadCache; friend class ThreadCache; - void base_run(Config config, + void base_run(const Config &config, void (*fn)(BenchHarnessBase *bench_harness_base, std::uint64_t iteration_count, std::uint32_t thread_num)); @@ -51,7 +51,7 @@ class BenchHarness final : private BenchHarnessBase : fn(std::move(fn)), input(std::move(input)) { } - void run(Config config) + void run(const Config &config) { base_run(config, [](BenchHarnessBase *bench_harness_base, std::uint64_t iteration_count, @@ -88,17 +88,17 @@ class Benchmark final { private: std::string m_name; - std::function m_run; + std::function m_run; public: template explicit Benchmark(Fn fn, Input input, std::string name) - : m_name(std::move(name)), m_run([fn, input](Config config) { + : m_name(std::move(name)), m_run([fn, input](const Config &config) { return BenchHarness(std::move(fn), std::move(input)).run(config); }) { } - void run(Config config) + void run(const Config &config) { return m_run(config); } diff --git a/src/powerpc64le/powerpc64le_benchmarks.cpp b/src/powerpc64le/powerpc64le_benchmarks.cpp index da0a672..f4f803e 100644 --- a/src/powerpc64le/powerpc64le_benchmarks.cpp +++ b/src/powerpc64le/powerpc64le_benchmarks.cpp @@ -3,7 +3,7 @@ #if defined(__powerpc64__) && BYTE_ORDER == LITTLE_ENDIAN -std::vector powerpc64le_benchmarks(Config config) +std::vector powerpc64le_benchmarks(const Config &config) { std::vector retval; // TODO: add powerpc64le benchmarks @@ -13,9 +13,9 @@ std::vector powerpc64le_benchmarks(Config config) #else -std::vector powerpc64le_benchmarks(Config) +std::vector powerpc64le_benchmarks(const Config &) { return {}; } -#endif \ No newline at end of file +#endif diff --git a/src/powerpc64le/powerpc64le_benchmarks.h b/src/powerpc64le/powerpc64le_benchmarks.h index 808685d..b4fbc14 100644 --- a/src/powerpc64le/powerpc64le_benchmarks.h +++ b/src/powerpc64le/powerpc64le_benchmarks.h @@ -2,4 +2,4 @@ #include "../harness.h" -std::vector powerpc64le_benchmarks(Config config); \ No newline at end of file +std::vector powerpc64le_benchmarks(const Config &config); diff --git a/src/x86_64/x86_64_benchmarks.cpp b/src/x86_64/x86_64_benchmarks.cpp index 9bc145f..83a02ff 100644 --- a/src/x86_64/x86_64_benchmarks.cpp +++ b/src/x86_64/x86_64_benchmarks.cpp @@ -2,7 +2,7 @@ #ifdef __x86_64__ -std::vector x86_64_benchmarks(Config config) +std::vector x86_64_benchmarks(const Config &config) { std::vector retval; // TODO: add x86_64 benchmarks @@ -12,9 +12,9 @@ std::vector x86_64_benchmarks(Config config) #else -std::vector x86_64_benchmarks(Config) +std::vector x86_64_benchmarks(const Config &) { return {}; } -#endif \ No newline at end of file +#endif diff --git a/src/x86_64/x86_64_benchmarks.h b/src/x86_64/x86_64_benchmarks.h index ed228af..7e93d42 100644 --- a/src/x86_64/x86_64_benchmarks.h +++ b/src/x86_64/x86_64_benchmarks.h @@ -2,4 +2,4 @@ #include "../harness.h" -std::vector x86_64_benchmarks(Config config); \ No newline at end of file +std::vector x86_64_benchmarks(const Config &config); -- 2.30.2