-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathquery-components-bench.cpp
47 lines (36 loc) · 1.33 KB
/
query-components-bench.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
#include <iostream>
#include <chrono>
// Windows > cl /O2 query-components-bench.cpp
// macOS > g++ /O2 query-components-bench.cpp -o bench
void execute(int& c1, int& c2, int& c3, int& c4, int& c5)
{
c1 = c2 + c3 + c4 + c5;
}
void benchmark(int* arr1, int* arr2, int* arr3, int* arr4, int* arr5, int count, int repeat)
{
for (int i = 0; i < repeat; i++) {
for (int n = 0; n < count; n++) {
execute(arr1[n], arr2[n], arr3[n], arr4[n], arr5[n]);
// arr1[n] = arr2[n] + arr3[n] + arr4[n] + arr5[n];
}
}
}
int main()
{
int count = 100000;
int repeat = 10000;
int* arr1 = new int[count];
int* arr2 = new int[count];
int* arr3 = new int[count];
int* arr4 = new int[count];
int* arr5 = new int[count];
std::chrono::steady_clock::time_point begin = std::chrono::steady_clock::now();
benchmark(arr1, arr2, arr3, arr4, arr5, count, repeat);
std::chrono::steady_clock::time_point end = std::chrono::steady_clock::now();
long duration = std::chrono::duration_cast<std::chrono::nanoseconds> (end - begin).count() / repeat;
std::cout << "entities: " << count << " duration: " << duration << " ns";
int dummy = 0;
for (int n = 0; n < count; n++)
dummy += arr1[n] + arr2[n] + arr3[n] + arr4[n] + arr5[n];
std::cout << "dummy: " << dummy;
}