Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions benchmarks/src/adjacent_difference.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include <type_traits>
#include <vector>

#include "skewed_allocator.hpp"

using namespace std;

template <class T>
Expand All @@ -19,8 +21,8 @@ void bm(benchmark::State& state) {

const size_t size = static_cast<size_t>(state.range(0));

vector<T> input(size);
vector<T> output(size);
vector<T, not_highly_aligned_allocator<T>> input(size);
vector<T, not_highly_aligned_allocator<T>> output(size);

if constexpr (is_floating_point_v<T>) {
normal_distribution<T> dis(0, 100000.0);
Expand Down
4 changes: 3 additions & 1 deletion benchmarks/src/adjacent_find.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include <cstdlib>
#include <vector>

#include "skewed_allocator.hpp"

using namespace std;

enum class AlgType { Std, Rng };
Expand All @@ -17,7 +19,7 @@ void bm(benchmark::State& state) {
const size_t size = static_cast<size_t>(state.range(0));
const size_t pos = static_cast<size_t>(state.range(1));

vector<T> v(size);
vector<T, not_highly_aligned_allocator<T>> v(size);

for (size_t i = 0; i != size; ++i) {
v[i] = static_cast<T>(i & 3);
Expand Down
4 changes: 3 additions & 1 deletion benchmarks/src/iota.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include <numeric>
#include <vector>

#include "skewed_allocator.hpp"

enum class Alg {
Std,
Rng,
Expand All @@ -16,7 +18,7 @@ template <class T, Alg Algorithm>
void bm(benchmark::State& state) {
const auto size = static_cast<std::size_t>(state.range(0));

std::vector<T> a(size);
std::vector<T, not_highly_aligned_allocator<T>> a(size);

for (auto _ : state) {
if constexpr (Algorithm == Alg::Std) {
Expand Down
4 changes: 3 additions & 1 deletion benchmarks/src/minmax_element.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#include <type_traits>
#include <vector>

#include "skewed_allocator.hpp"

enum class Op {
Min,
Max,
Expand All @@ -23,7 +25,7 @@ using namespace std;

template <class T, Op Operation>
void bm(benchmark::State& state) {
vector<T> a(static_cast<size_t>(state.range()));
vector<T, not_highly_aligned_allocator<T>> a(static_cast<size_t>(state.range()));

mt19937 gen(84710);

Expand Down
6 changes: 4 additions & 2 deletions benchmarks/src/mismatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include <ranges>
#include <vector>

#include "skewed_allocator.hpp"

using namespace std;

constexpr int64_t no_pos = -1;
Expand All @@ -19,8 +21,8 @@ enum class op {

template <class T, op Op>
void bm(benchmark::State& state) {
vector<T> a(static_cast<size_t>(state.range(0)), T{'.'});
vector<T> b(static_cast<size_t>(state.range(0)), T{'.'});
vector<T, not_highly_aligned_allocator<T>> a(static_cast<size_t>(state.range(0)), T{'.'});
vector<T, not_highly_aligned_allocator<T>> b(static_cast<size_t>(state.range(0)), T{'.'});

if (state.range(1) != no_pos) {
b.at(static_cast<size_t>(state.range(1))) = 'x';
Expand Down
9 changes: 5 additions & 4 deletions benchmarks/src/remove.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
#include <vector>

#include "lorem.hpp"
#include "skewed_allocator.hpp"

enum class alg_type { std_fn, rng };

template <alg_type Type, class T>
void r(benchmark::State& state) {
const std::vector<T> src(lorem_ipsum.begin(), lorem_ipsum.end());
std::vector<T> v;
const std::vector<T, not_highly_aligned_allocator<T>> src(lorem_ipsum.begin(), lorem_ipsum.end());
std::vector<T, not_highly_aligned_allocator<T>> v;
v.reserve(lorem_ipsum.size());
for (auto _ : state) {
v = src;
Expand All @@ -28,8 +29,8 @@ void r(benchmark::State& state) {

template <alg_type Type, class T>
void rc(benchmark::State& state) {
std::vector<T> src(lorem_ipsum.begin(), lorem_ipsum.end());
std::vector<T> v(lorem_ipsum.size());
std::vector<T, not_highly_aligned_allocator<T>> src(lorem_ipsum.begin(), lorem_ipsum.end());
std::vector<T, not_highly_aligned_allocator<T>> v(lorem_ipsum.size());
for (auto _ : state) {
benchmark::DoNotOptimize(src);
benchmark::DoNotOptimize(v);
Expand Down
19 changes: 13 additions & 6 deletions benchmarks/src/replace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,43 @@
#include <vector>

#include "lorem.hpp"
#include "skewed_allocator.hpp"

template <class T>
void r(benchmark::State& state) {
const std::vector<T> a(lorem_ipsum.begin(), lorem_ipsum.end());
std::vector<T> b(lorem_ipsum.size());
std::vector<T, not_highly_aligned_allocator<T>> a(lorem_ipsum.begin(), lorem_ipsum.end());
std::vector<T, not_highly_aligned_allocator<T>> 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 <class T>
void rc(benchmark::State& state) {
const std::vector<T> a(lorem_ipsum.begin(), lorem_ipsum.end());
std::vector<T> b(lorem_ipsum.size());
std::vector<T, not_highly_aligned_allocator<T>> a(lorem_ipsum.begin(), lorem_ipsum.end());
std::vector<T, not_highly_aligned_allocator<T>> 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 <class T>
void rc_if(benchmark::State& state) {
const std::vector<T> a(lorem_ipsum.begin(), lorem_ipsum.end());
std::vector<T> b(lorem_ipsum.size());
std::vector<T, not_highly_aligned_allocator<T>> a(lorem_ipsum.begin(), lorem_ipsum.end());
std::vector<T, not_highly_aligned_allocator<T>> 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);
}
}

Expand Down
25 changes: 13 additions & 12 deletions benchmarks/src/std_copy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@
#include <type_traits>
#include <vector>

#include <udt.hpp>
#include <utility.hpp>
#include "skewed_allocator.hpp"
#include "udt.hpp"
#include "utility.hpp"

template <typename Contained>
void handwritten_loop(benchmark::State& state) {
const size_t r0 = static_cast<size_t>(state.range(0));
const auto in_buffer = random_vector<Contained>(r0);
std::vector<Contained> out_buffer(r0);
const auto in_buffer = random_vector<Contained, not_highly_aligned_allocator>(r0);
std::vector<Contained, not_highly_aligned_allocator<Contained>> out_buffer(r0);
for ([[maybe_unused]] auto _ : state) {
benchmark::DoNotOptimize(in_buffer.data());
const Contained* in_ptr = in_buffer.data();
Expand All @@ -32,8 +33,8 @@ void handwritten_loop(benchmark::State& state) {
template <typename Contained>
void handwritten_loop_n(benchmark::State& state) {
const size_t r0 = static_cast<size_t>(state.range(0));
const auto in_buffer = random_vector<Contained>(r0);
std::vector<Contained> out_buffer(r0);
const auto in_buffer = random_vector<Contained, not_highly_aligned_allocator>(r0);
std::vector<Contained, not_highly_aligned_allocator<Contained>> out_buffer(r0);
for ([[maybe_unused]] auto _ : state) {
benchmark::DoNotOptimize(in_buffer.data());
const Contained* const in_ptr = in_buffer.data();
Expand All @@ -50,8 +51,8 @@ template <typename Contained>
void memcpy_call(benchmark::State& state) {
static_assert(std::is_trivially_copyable_v<Contained>, "memcpy must only be called on trivially copyable types");
const size_t r0 = static_cast<size_t>(state.range(0));
const auto in_buffer = random_vector<Contained>(r0);
std::vector<Contained> out_buffer(r0);
const auto in_buffer = random_vector<Contained, not_highly_aligned_allocator>(r0);
std::vector<Contained, not_highly_aligned_allocator<Contained>> out_buffer(r0);
for ([[maybe_unused]] auto _ : state) {
benchmark::DoNotOptimize(in_buffer.data());
memcpy(out_buffer.data(), in_buffer.data(), r0 * sizeof(Contained));
Expand All @@ -62,8 +63,8 @@ void memcpy_call(benchmark::State& state) {
template <typename Contained>
void std_copy_call(benchmark::State& state) {
const size_t r0 = static_cast<size_t>(state.range(0));
const auto in_buffer = random_vector<Contained>(r0);
std::vector<Contained> out_buffer(r0);
const auto in_buffer = random_vector<Contained, not_highly_aligned_allocator>(r0);
std::vector<Contained, not_highly_aligned_allocator<Contained>> out_buffer(r0);
for ([[maybe_unused]] auto _ : state) {
benchmark::DoNotOptimize(in_buffer.data());
std::copy(in_buffer.begin(), in_buffer.end(), out_buffer.begin());
Expand All @@ -74,8 +75,8 @@ void std_copy_call(benchmark::State& state) {
template <typename Contained>
void std_copy_n_call(benchmark::State& state) {
const size_t r0 = static_cast<size_t>(state.range(0));
const auto in_buffer = random_vector<Contained>(r0);
std::vector<Contained> out_buffer(r0);
const auto in_buffer = random_vector<Contained, not_highly_aligned_allocator>(r0);
std::vector<Contained, not_highly_aligned_allocator<Contained>> out_buffer(r0);
for ([[maybe_unused]] auto _ : state) {
benchmark::DoNotOptimize(in_buffer.data());
std::copy_n(in_buffer.begin(), r0, out_buffer.begin());
Expand Down