-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAoS_vs_SoA.cpp
54 lines (47 loc) · 891 Bytes
/
AoS_vs_SoA.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
#include "stdafx.h"
#include <iostream>
#include <string>
#include <unordered_map>
#include <bitset>
#include <memory>
using namespace std;
// AoS
// A0 B0 C0 A1 B1 C1
struct Quadratic {
public:
float a, b, c;
};
// SoA
// in the RAM
// A0 A1 A2
// B0 B1 B2
// C0 C1 C2
struct Quadratics {
public:
float a[1 << 24];
float b[1 << 24];
float c[1 << 24];
} quads;
int main()
{
const int count = 1 << 24; // 16 million
// ---- AoS ----
Quadratic* e = new Quadratic[count]; // AoS
float* roots = new float[count];
// Random quadratrics
for (int i = 0; i < count; i++)
{
e[i].a = (rand() % 100) - 50;
e[i].b = (rand() % 100) - 50;
e[i].c = (rand() % 100) - 50;
}
// ---- SoA ----
// Random quadratrics
for (int i = 0; i < count; i++)
{
quads.a[i] = (rand() % 100) - 50;
quads.b[i] = (rand() % 100) - 50;
quads.c[i] = (rand() % 100) - 50;
}
return 0;
}