From a2912514dbcf33828107d906d392ac9ae337bb7b Mon Sep 17 00:00:00 2001 From: Alex Guteniev Date: Sat, 26 Apr 2025 19:37:16 +0300 Subject: [PATCH] Benchmark: use not_higghly_aligned allocator in more places --- benchmarks/src/adjacent_difference.cpp | 6 ++++-- benchmarks/src/adjacent_find.cpp | 4 +++- benchmarks/src/iota.cpp | 4 +++- benchmarks/src/minmax_element.cpp | 4 +++- benchmarks/src/mismatch.cpp | 6 ++++-- benchmarks/src/remove.cpp | 9 +++++---- benchmarks/src/replace.cpp | 19 +++++++++++++------ benchmarks/src/std_copy.cpp | 25 +++++++++++++------------ 8 files changed, 48 insertions(+), 29 deletions(-) diff --git a/benchmarks/src/adjacent_difference.cpp b/benchmarks/src/adjacent_difference.cpp index b8ea76d8e2f..798bc813beb 100644 --- a/benchmarks/src/adjacent_difference.cpp +++ b/benchmarks/src/adjacent_difference.cpp @@ -11,6 +11,8 @@ #include #include +#include "skewed_allocator.hpp" + using namespace std; template @@ -19,8 +21,8 @@ void bm(benchmark::State& state) { const size_t size = static_cast(state.range(0)); - vector input(size); - vector output(size); + vector> input(size); + vector> output(size); if constexpr (is_floating_point_v) { normal_distribution dis(0, 100000.0); diff --git a/benchmarks/src/adjacent_find.cpp b/benchmarks/src/adjacent_find.cpp index 67036be67bf..1e1aee08bb4 100644 --- a/benchmarks/src/adjacent_find.cpp +++ b/benchmarks/src/adjacent_find.cpp @@ -8,6 +8,8 @@ #include #include +#include "skewed_allocator.hpp" + using namespace std; enum class AlgType { Std, Rng }; @@ -17,7 +19,7 @@ void bm(benchmark::State& state) { const size_t size = static_cast(state.range(0)); const size_t pos = static_cast(state.range(1)); - vector v(size); + vector> v(size); for (size_t i = 0; i != size; ++i) { v[i] = static_cast(i & 3); diff --git a/benchmarks/src/iota.cpp b/benchmarks/src/iota.cpp index 5860b1b605e..d1bd8b97807 100644 --- a/benchmarks/src/iota.cpp +++ b/benchmarks/src/iota.cpp @@ -7,6 +7,8 @@ #include #include +#include "skewed_allocator.hpp" + enum class Alg { Std, Rng, @@ -16,7 +18,7 @@ template void bm(benchmark::State& state) { const auto size = static_cast(state.range(0)); - std::vector a(size); + std::vector> a(size); for (auto _ : state) { if constexpr (Algorithm == Alg::Std) { diff --git a/benchmarks/src/minmax_element.cpp b/benchmarks/src/minmax_element.cpp index e009610e4c3..8a649502c3f 100644 --- a/benchmarks/src/minmax_element.cpp +++ b/benchmarks/src/minmax_element.cpp @@ -10,6 +10,8 @@ #include #include +#include "skewed_allocator.hpp" + enum class Op { Min, Max, @@ -23,7 +25,7 @@ using namespace std; template void bm(benchmark::State& state) { - vector a(static_cast(state.range())); + vector> a(static_cast(state.range())); mt19937 gen(84710); diff --git a/benchmarks/src/mismatch.cpp b/benchmarks/src/mismatch.cpp index 2efe44a0a21..f604ceff4fb 100644 --- a/benchmarks/src/mismatch.cpp +++ b/benchmarks/src/mismatch.cpp @@ -8,6 +8,8 @@ #include #include +#include "skewed_allocator.hpp" + using namespace std; constexpr int64_t no_pos = -1; @@ -19,8 +21,8 @@ enum class op { template void bm(benchmark::State& state) { - vector a(static_cast(state.range(0)), T{'.'}); - vector b(static_cast(state.range(0)), T{'.'}); + vector> a(static_cast(state.range(0)), T{'.'}); + vector> b(static_cast(state.range(0)), T{'.'}); if (state.range(1) != no_pos) { b.at(static_cast(state.range(1))) = 'x'; diff --git a/benchmarks/src/remove.cpp b/benchmarks/src/remove.cpp index 92ca87534a9..61a7b772918 100644 --- a/benchmarks/src/remove.cpp +++ b/benchmarks/src/remove.cpp @@ -7,13 +7,14 @@ #include #include "lorem.hpp" +#include "skewed_allocator.hpp" enum class alg_type { std_fn, rng }; template void r(benchmark::State& state) { - const std::vector src(lorem_ipsum.begin(), lorem_ipsum.end()); - std::vector v; + const std::vector> src(lorem_ipsum.begin(), lorem_ipsum.end()); + std::vector> v; v.reserve(lorem_ipsum.size()); for (auto _ : state) { v = src; @@ -28,8 +29,8 @@ void r(benchmark::State& state) { template void rc(benchmark::State& state) { - std::vector src(lorem_ipsum.begin(), lorem_ipsum.end()); - std::vector v(lorem_ipsum.size()); + std::vector> src(lorem_ipsum.begin(), lorem_ipsum.end()); + std::vector> v(lorem_ipsum.size()); for (auto _ : state) { benchmark::DoNotOptimize(src); benchmark::DoNotOptimize(v); diff --git a/benchmarks/src/replace.cpp b/benchmarks/src/replace.cpp index 7a41e041569..ebb1aa038bf 100644 --- a/benchmarks/src/replace.cpp +++ b/benchmarks/src/replace.cpp @@ -7,36 +7,43 @@ #include #include "lorem.hpp" +#include "skewed_allocator.hpp" template void r(benchmark::State& state) { - const std::vector a(lorem_ipsum.begin(), lorem_ipsum.end()); - std::vector b(lorem_ipsum.size()); + std::vector> a(lorem_ipsum.begin(), lorem_ipsum.end()); + std::vector> b(lorem_ipsum.size()); for (auto _ : state) { + benchmark::DoNotOptimize(a); b = a; std::replace(std::begin(b), std::end(b), T{'m'}, T{'w'}); + benchmark::DoNotOptimize(b); } } template void rc(benchmark::State& state) { - const std::vector a(lorem_ipsum.begin(), lorem_ipsum.end()); - std::vector b(lorem_ipsum.size()); + std::vector> a(lorem_ipsum.begin(), lorem_ipsum.end()); + std::vector> b(lorem_ipsum.size()); for (auto _ : state) { + benchmark::DoNotOptimize(a); std::replace_copy(std::begin(a), std::end(a), std::begin(b), T{'m'}, T{'w'}); + benchmark::DoNotOptimize(b); } } template void rc_if(benchmark::State& state) { - const std::vector a(lorem_ipsum.begin(), lorem_ipsum.end()); - std::vector b(lorem_ipsum.size()); + std::vector> a(lorem_ipsum.begin(), lorem_ipsum.end()); + std::vector> b(lorem_ipsum.size()); for (auto _ : state) { + benchmark::DoNotOptimize(a); (void) std::replace_copy_if( std::begin(a), std::end(a), std::begin(b), [](auto x) { return x <= T{'Z'}; }, T{'X'}); + benchmark::DoNotOptimize(b); } } diff --git a/benchmarks/src/std_copy.cpp b/benchmarks/src/std_copy.cpp index 40c2cb7c148..eba6cbc2314 100644 --- a/benchmarks/src/std_copy.cpp +++ b/benchmarks/src/std_copy.cpp @@ -8,14 +8,15 @@ #include #include -#include -#include +#include "skewed_allocator.hpp" +#include "udt.hpp" +#include "utility.hpp" template void handwritten_loop(benchmark::State& state) { const size_t r0 = static_cast(state.range(0)); - const auto in_buffer = random_vector(r0); - std::vector out_buffer(r0); + const auto in_buffer = random_vector(r0); + std::vector> out_buffer(r0); for ([[maybe_unused]] auto _ : state) { benchmark::DoNotOptimize(in_buffer.data()); const Contained* in_ptr = in_buffer.data(); @@ -32,8 +33,8 @@ void handwritten_loop(benchmark::State& state) { template void handwritten_loop_n(benchmark::State& state) { const size_t r0 = static_cast(state.range(0)); - const auto in_buffer = random_vector(r0); - std::vector out_buffer(r0); + const auto in_buffer = random_vector(r0); + std::vector> out_buffer(r0); for ([[maybe_unused]] auto _ : state) { benchmark::DoNotOptimize(in_buffer.data()); const Contained* const in_ptr = in_buffer.data(); @@ -50,8 +51,8 @@ template void memcpy_call(benchmark::State& state) { static_assert(std::is_trivially_copyable_v, "memcpy must only be called on trivially copyable types"); const size_t r0 = static_cast(state.range(0)); - const auto in_buffer = random_vector(r0); - std::vector out_buffer(r0); + const auto in_buffer = random_vector(r0); + std::vector> out_buffer(r0); for ([[maybe_unused]] auto _ : state) { benchmark::DoNotOptimize(in_buffer.data()); memcpy(out_buffer.data(), in_buffer.data(), r0 * sizeof(Contained)); @@ -62,8 +63,8 @@ void memcpy_call(benchmark::State& state) { template void std_copy_call(benchmark::State& state) { const size_t r0 = static_cast(state.range(0)); - const auto in_buffer = random_vector(r0); - std::vector out_buffer(r0); + const auto in_buffer = random_vector(r0); + std::vector> out_buffer(r0); for ([[maybe_unused]] auto _ : state) { benchmark::DoNotOptimize(in_buffer.data()); std::copy(in_buffer.begin(), in_buffer.end(), out_buffer.begin()); @@ -74,8 +75,8 @@ void std_copy_call(benchmark::State& state) { template void std_copy_n_call(benchmark::State& state) { const size_t r0 = static_cast(state.range(0)); - const auto in_buffer = random_vector(r0); - std::vector out_buffer(r0); + const auto in_buffer = random_vector(r0); + std::vector> out_buffer(r0); for ([[maybe_unused]] auto _ : state) { benchmark::DoNotOptimize(in_buffer.data()); std::copy_n(in_buffer.begin(), r0, out_buffer.begin());