-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
51 lines (45 loc) · 1023 Bytes
/
main.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
#include <iostream>
#include "utils/benchmark.h"
constexpr int kSize = 100000000;
static_assert(kSize % 10 == 0, "kSize must be a multiple of 10 to unroll");
void loop_unroll(std::vector<int> *data)
{
for (int j = 0; j < kSize; j += 10)
{
(*data)[j]++;
(*data)[j + 1]++;
(*data)[j + 2]++;
(*data)[j + 3]++;
(*data)[j + 4]++;
(*data)[j + 5]++;
(*data)[j + 6]++;
(*data)[j + 7]++;
(*data)[j + 8]++;
(*data)[j + 9]++;
}
}
void loop_unroll_with_pragma_unroll(std::vector<int> *data)
{
#pragma unroll 10
for (int j = 0; j < kSize; ++j)
{
(*data)[j]++;
}
}
void no_loop_unroll(std::vector<int> *data)
{
for (int i = 0; i < kSize; ++i)
{
(*data)[i]++;
}
}
int main(int argc, char* argv[])
{
std::vector<int> data(kSize, 0);
auto bench = BENCHMARKING(
loop_unroll,
loop_unroll_with_pragma_unroll,
no_loop_unroll
);
return bench.run(argc, argv, &data);
}