forked from cassioneri/sort3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbenchmark.cpp
More file actions
130 lines (116 loc) · 2.82 KB
/
Copy pathbenchmark.cpp
File metadata and controls
130 lines (116 loc) · 2.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2023 Cassio Neri <cassio.neri@gmail.com>
//
// This code is a supplementary material to:
//
// Neri, C. "Shorter and faster than Sort3AlphaDev", to appear.
// Preprint: https://arxiv.org/abs/2307.14503.
#include "sort.h"
#include <benchmark/benchmark.h>
#include <array>
#include <cstdint>
#include <iterator>
#include <random>
std::array<int , 3> const test_cases[] = {
{ 1, 2, 3 },
{ 1, 3, 2 },
{ 2, 1, 3 },
{ 2, 3, 1 },
{ 3, 1, 2 },
{ 3, 2, 1 },
{ 1, 1, 2 },
{ 1, 2, 1 },
{ 2, 1, 1 },
{ 2, 2, 1 },
{ 2, 1, 2 },
{ 1, 2, 2 },
{ 1, 1, 1 },
};
auto ns = [](){
std::uniform_int_distribution<unsigned> uniform_dist(0, std::size(test_cases) - 1);
std::mt19937 rng;
std::array<int32_t, 32768> ns;
for (auto& n : ns)
n = uniform_dist(rng);
return ns;
}();
static void Scanning(benchmark::State& state) {
for (auto _ : state)
for (auto n : ns) {
auto p = test_cases[n];
benchmark::DoNotOptimize(p.data());
}
}
BENCHMARK(Scanning);
static void Sort3AlphaDev(benchmark::State& state) {
for (auto _ : state)
for (auto n : ns) {
auto p = test_cases[n];
Sort3AlphaDev(p.data());
benchmark::DoNotOptimize(p.data());
}
}
BENCHMARK(Sort3AlphaDev);
static void Sort3_14(benchmark::State& state) {
for (auto _ : state)
for (auto n : ns) {
auto p = test_cases[n];
Sort3_14(p.data());
benchmark::DoNotOptimize(p.data());
}
}
BENCHMARK(Sort3_14);
static void Sort3_beat(benchmark::State& state) {
for (auto _ : state)
for (auto n : ns) {
auto p = test_cases[n];
Sort3_beat(p.data());
benchmark::DoNotOptimize(p.data());
}
}
BENCHMARK(Sort3_beat);
static void Sort3_10(benchmark::State& state) {
for (auto _ : state)
for (auto n : ns) {
auto p = test_cases[n];
Sort3_10(p.data());
benchmark::DoNotOptimize(p.data());
}
}
BENCHMARK(Sort3_10);
static void Sort3_12(benchmark::State& state) {
for (auto _ : state)
for (auto n : ns) {
auto p = test_cases[n];
Sort3_12(p.data());
benchmark::DoNotOptimize(p.data());
}
}
BENCHMARK(Sort3_12);
static void Sort3_15(benchmark::State& state) {
for (auto _ : state)
for (auto n : ns) {
auto p = test_cases[n];
Sort3_15(p.data());
benchmark::DoNotOptimize(p.data());
}
}
BENCHMARK(Sort3_15);
static void Sort3_15_v2(benchmark::State& state) {
for (auto _ : state)
for (auto n : ns) {
auto p = test_cases[n];
Sort3_15_v2(p.data());
benchmark::DoNotOptimize(p.data());
}
}
BENCHMARK(Sort3_15_v2);
static void Sort3_faster(benchmark::State& state) {
for (auto _ : state)
for (auto n : ns) {
auto p = test_cases[n];
Sort3_faster(p.data());
benchmark::DoNotOptimize(p.data());
}
}
BENCHMARK(Sort3_faster);