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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
use std::hint::black_box;
use std::path::PathBuf;
use criterion::{criterion_group, criterion_main, Criterion};
use ecs::{Component, World};
fn fibonacci(n: u64) -> u64
{
match n {
0 => 1,
1 => 1,
n => fibonacci(n - 1) + fibonacci(n - 2),
}
}
#[derive(Component)]
struct Foo
{
text: String,
}
#[derive(Component)]
struct Bar
{
path: PathBuf,
num: u64,
}
#[derive(Component)]
struct Position
{
x: f32,
y: f32,
z: f32,
}
#[derive(Component)]
struct PosA
{
x: f32,
y: f32,
z: f32,
}
#[derive(Component)]
struct PosB
{
x: f32,
y: f32,
z: f32,
}
#[derive(Component)]
struct PosC
{
x: f32,
y: f32,
z: f32,
}
#[derive(Component)]
struct MoreText
{
more_text: String,
}
#[derive(Component)]
struct EvenMoreText
{
even_more_text: String,
}
fn criterion_benchmark(criterion: &mut Criterion)
{
let mut world = World::new();
for _ in 0..300 {
world.create_entity((
Bar { path: "/dev/zero".into(), num: 65789 },
Position { x: 13.98, y: 27.0, z: 0.2 },
Foo { text: "Hello there".to_string() },
PosA { x: 1183.98, y: 272628.0, z: 3306.2 },
PosB { x: 171183.98, y: 28.0, z: 336.2901 },
PosC { x: 8273.98, y: 28.0, z: 336.2901 },
MoreText { more_text: "Lorem ipsum".to_string() },
EvenMoreText {
even_more_text: "Wow so much text".to_string(),
},
));
}
for _ in 0..700 {
world.create_entity((
Bar { path: "/dev/null".into(), num: 65789 },
Position { x: 88.11, y: 9.0, z: 36.11 },
Foo { text: "Hey".to_string() },
PosA { x: 118310.98, y: 272628.0, z: 3306.2 },
PosB { x: 11323.98, y: 28.0, z: 336.2901 },
PosC { x: 8273.98, y: 21818.0, z: 336.2901 },
MoreText { more_text: "Lorem ipsum".to_string() },
EvenMoreText {
even_more_text: "Wow much text".to_string(),
},
));
}
let query = world.query::<(Bar, Position, Foo), ()>();
criterion.bench_function("fib 20", |bencher| {
bencher.iter(|| {
for comps in query.iter() {
black_box(comps);
}
})
});
}
criterion_group!(benches, criterion_benchmark);
criterion_main!(benches);
|