Celero
experiments
ExperimentParticles
Particles.h
1
// Original code at: https://github.com/fenbf/benchmarkLibsTest
2
#pragma once
3
4
static
int
randSeed = 10;
5
inline
float
randF()
6
{
7
return
0.01f * (float)((randSeed++) % 100);
8
}
9
10
static
const
size_t
UPDATES = 1000;
11
static
const
float
DELTA_TIME = 1.0f / 60.0f;
12
13
template
<
int
BufSize = 1>
14
class
TParticle
15
{
16
private
:
17
float
pos[4];
18
float
acc[4];
19
float
vel[4];
20
float
col[4];
21
float
rot;
22
float
time;
23
float
buf[BufSize];
24
25
public
:
26
void
generate()
27
{
28
acc[0] = randF();
29
acc[1] = randF();
30
acc[2] = randF();
31
acc[3] = randF();
32
pos[0] = pos[1] = pos[2] = pos[3] = 0.0f;
33
vel[0] = randF();
34
vel[1] = randF();
35
vel[2] = randF();
36
vel[3] = vel[1] + vel[2];
37
rot = 0.0f;
38
time = 2.0f + randF();
39
}
40
41
void
update(
float
dt)
42
{
43
vel[0] += acc[0] * dt;
44
vel[1] += acc[1] * dt;
45
vel[2] += acc[2] * dt;
46
vel[3] += acc[3] * dt;
47
pos[0] += vel[0] * dt;
48
pos[1] += vel[1] * dt;
49
pos[2] += vel[2] * dt;
50
pos[3] += vel[3] * dt;
51
col[0] = pos[0] * 0.001f;
52
col[1] = pos[1] * 0.001f;
53
col[2] = pos[2] * 0.001f;
54
col[3] = pos[3] * 0.001f;
55
rot += vel[3] * dt;
56
time -= dt;
57
58
for
(
int
i = 0; i < BufSize; ++i)
59
{
60
buf[i] = vel[i % 4] + vel[i % 4] + vel[2] + pos[0] + pos[1] + pos[i % 4];
61
}
62
63
if
(time < 0.0f)
64
{
65
generate();
66
}
67
}
68
};
69
70
using
Particle
=
TParticle<1>
;
// sizeof 19*float = 76bytes
71
using
Particle160
=
TParticle<22>
;
// sizeof (18 + 22)*float = 160 bytes
TParticle
Definition:
Particles.h:14
Generated by
1.8.13