forked from gordonl0811/LowLatencyProgramming
-
Notifications
You must be signed in to change notification settings - Fork 0
/
benchmark.cpp
47 lines (32 loc) · 1.31 KB
/
benchmark.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
#include <benchmark/benchmark.h>
#include "loop_unrolling.h"
#include <vector>
#include "../utils/utils.h"
static void BenchmarkSumVectors(benchmark::State& state) {
int size = (int) state.range(0);
std::vector<int> x = GenerateRandomInts(size);
std::vector<int> y = GenerateRandomInts(size);
for (auto _ : state) {
benchmark::DoNotOptimize(LoopUnrolling::SumVectors(x, y, size));
}
}
static void BenchmarkSumVectorsUnrolledTwo(benchmark::State& state) {
int size = (int) state.range(0);
std::vector<int> x = GenerateRandomInts(size);
std::vector<int> y = GenerateRandomInts(size);
for (auto _ : state) {
benchmark::DoNotOptimize(LoopUnrolling::SumVectorsUnrolledTwo(x, y, size));
}
}
static void BenchmarkSumVectorsUnrolledFour(benchmark::State& state) {
int size = (int) state.range(0);
std::vector<int> x = GenerateRandomInts(size);
std::vector<int> y = GenerateRandomInts(size);
for (auto _ : state) {
benchmark::DoNotOptimize(LoopUnrolling::SumVectorsUnrolledFour(x, y, size));
}
}
BENCHMARK(BenchmarkSumVectors)->RangeMultiplier(8)->Range(8, 4096*4096);
BENCHMARK(BenchmarkSumVectorsUnrolledTwo)->RangeMultiplier(8)->Range(8, 4096*4096);
BENCHMARK(BenchmarkSumVectorsUnrolledFour)->RangeMultiplier(8)->Range(8, 4096*4096);
BENCHMARK_MAIN();