|
| 1 | +// Copyright (c) Microsoft Corporation. |
| 2 | +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 3 | + |
| 4 | +#include <algorithm> |
| 5 | +#include <benchmark/benchmark.h> |
| 6 | +#include <cstdint> |
| 7 | +#include <vector> |
| 8 | + |
| 9 | +#include "skewed_allocator.hpp" |
| 10 | +#include "utility.hpp" |
| 11 | + |
| 12 | +template <class T> |
| 13 | +void r(benchmark::State& state) { |
| 14 | + const auto size = static_cast<size_t>(state.range(0)); |
| 15 | + auto v = random_vector<T, not_highly_aligned_allocator>(size); |
| 16 | + |
| 17 | + for (auto _ : state) { |
| 18 | + benchmark::DoNotOptimize(v); |
| 19 | + std::reverse(v.begin(), v.end()); |
| 20 | + } |
| 21 | +} |
| 22 | + |
| 23 | +template <class T> |
| 24 | +void rc(benchmark::State& state) { |
| 25 | + const auto size = static_cast<size_t>(state.range(0)); |
| 26 | + auto v = random_vector<T, not_highly_aligned_allocator>(size); |
| 27 | + std::vector<T, not_highly_aligned_allocator<T>> d(size); |
| 28 | + |
| 29 | + for (auto _ : state) { |
| 30 | + benchmark::DoNotOptimize(v); |
| 31 | + std::reverse_copy(v.begin(), v.end(), d.begin()); |
| 32 | + benchmark::DoNotOptimize(d); |
| 33 | + } |
| 34 | +} |
| 35 | + |
| 36 | +void common_args(auto bm) { |
| 37 | + bm->Arg(3449); |
| 38 | + // AVX tail tests |
| 39 | + bm->Arg(63)->Arg(31)->Arg(15)->Arg(7); |
| 40 | +} |
| 41 | + |
| 42 | + |
| 43 | +BENCHMARK(r<std::uint8_t>)->Apply(common_args); |
| 44 | +BENCHMARK(r<std::uint16_t>)->Apply(common_args); |
| 45 | +BENCHMARK(r<std::uint32_t>)->Apply(common_args); |
| 46 | +BENCHMARK(r<std::uint64_t>)->Apply(common_args); |
| 47 | + |
| 48 | +BENCHMARK(rc<std::uint8_t>)->Apply(common_args); |
| 49 | +BENCHMARK(rc<std::uint16_t>)->Apply(common_args); |
| 50 | +BENCHMARK(rc<std::uint32_t>)->Apply(common_args); |
| 51 | +BENCHMARK(rc<std::uint64_t>)->Apply(common_args); |
| 52 | + |
| 53 | +BENCHMARK_MAIN(); |
0 commit comments