-
Notifications
You must be signed in to change notification settings - Fork 2
/
Sort8Benchmark.cpp
59 lines (50 loc) · 1.3 KB
/
Sort8Benchmark.cpp
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
/*
brew install folly gflags
g++ -g -std=c++17 -msse4 -O2 -DNDEBUG -c Sort8.cpp &&
g++ -g -std=c++17 -msse4 -O2 -DNDEBUG -lfollybenchmark -lgflags Sort8.o Sort8Benchmark.cpp
*/
#include "Sort8.hpp"
#include <emmintrin.h>
#include <cstddef>
#include <cstdint>
#include <algorithm>
#include <limits>
#include <random>
#include <folly/Benchmark.h>
#include <gflags/gflags.h>
using namespace folly;
using namespace std;
namespace {
constexpr size_t kArity = 8;
constexpr size_t kCount = 10000;
__m128i mms[kCount];
void initData() {
default_random_engine gen(0);
uniform_int_distribution<uint16_t> distr(0, numeric_limits<uint16_t>::max());
uint16_t* vs = reinterpret_cast<uint16_t*>(mms);
for (size_t i = 0; i < kCount * kArity; ++i) vs[i] = distr(gen);
}
} // namespace
BENCHMARK(sort8) {
__m128i x = _mm_set1_epi16(0);
for (size_t j = 0; j < kCount; ++j) {
x ^= sort8(mms[j]);
}
doNotOptimizeAway(x);
}
BENCHMARK_RELATIVE(std_sort) {
__m128i x = _mm_set1_epi16(0);
for (size_t j = 0; j < kCount; ++j) {
__m128i tmp = mms[j];
uint16_t* vs = reinterpret_cast<uint16_t*>(&tmp);
std::sort(vs, vs + kArity);
x ^= tmp;
}
doNotOptimizeAway(x);
}
int main(int argc, char** argv) {
gflags::ParseCommandLineFlags(&argc, &argv, true);
initData();
runBenchmarks();
return 0;
}