Skip to content

Commit 2ce34fd

Browse files
Benchmark vectorized reverse and reverse_copy, use traits, optimize reverse_copy tail (#5493)
Co-authored-by: Stephan T. Lavavej <[email protected]>
1 parent d6155d4 commit 2ce34fd

File tree

3 files changed

+216
-281
lines changed

3 files changed

+216
-281
lines changed

benchmarks/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ add_benchmark(priority_queue_push_range src/priority_queue_push_range.cpp)
118118
add_benchmark(random_integer_generation src/random_integer_generation.cpp)
119119
add_benchmark(remove src/remove.cpp)
120120
add_benchmark(replace src/replace.cpp)
121+
add_benchmark(reverse src/reverse.cpp)
121122
add_benchmark(search src/search.cpp)
122123
add_benchmark(search_n src/search_n.cpp)
123124
add_benchmark(std_copy src/std_copy.cpp)

benchmarks/src/reverse.cpp

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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

Comments
 (0)