Skip to content
This repository was archived by the owner on Nov 27, 2022. It is now read-only.

Commit 4ff4761

Browse files
committed
Add Edict ECS to the suite
1 parent d9c108a commit 4ff4761

File tree

8 files changed

+157
-0
lines changed

8 files changed

+157
-0
lines changed

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ serde = { version = "1.0", features = ["derive"] }
2020
shipyard = "0.5.0"
2121
specs = {version = "0.16.1", features = ["serde"] }
2222
specs-derive = "0.4.1"
23+
edict = { version = "0.0.3" }
2324

2425
[dev-dependencies]
2526
criterion = "0.3"

benches/benchmarks.rs

+16
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ fn bench_simple_insert(c: &mut Criterion) {
2727
let mut bench = specs::simple_insert::Benchmark::new();
2828
b.iter(move || bench.run());
2929
});
30+
group.bench_function("edict", |b| {
31+
let mut bench = edict::simple_insert::Benchmark::new();
32+
b.iter(move || bench.run());
33+
});
3034
}
3135

3236
fn bench_simple_iter(c: &mut Criterion) {
@@ -59,6 +63,10 @@ fn bench_simple_iter(c: &mut Criterion) {
5963
let mut bench = specs::simple_iter::Benchmark::new();
6064
b.iter(move || bench.run());
6165
});
66+
group.bench_function("edict", |b| {
67+
let mut bench = edict::simple_iter::Benchmark::new();
68+
b.iter(move || bench.run());
69+
});
6270
}
6371

6472
fn bench_frag_iter_bc(c: &mut Criterion) {
@@ -87,6 +95,10 @@ fn bench_frag_iter_bc(c: &mut Criterion) {
8795
let mut bench = specs::frag_iter::Benchmark::new();
8896
b.iter(move || bench.run());
8997
});
98+
group.bench_function("edict", |b| {
99+
let mut bench = edict::frag_iter::Benchmark::new();
100+
b.iter(move || bench.run());
101+
});
90102
}
91103

92104
fn bench_schedule(c: &mut Criterion) {
@@ -171,6 +183,10 @@ fn bench_add_remove(c: &mut Criterion) {
171183
let mut bench = bevy::add_remove::Benchmark::new();
172184
b.iter(move || bench.run());
173185
});
186+
group.bench_function("edict", |b| {
187+
let mut bench = edict::add_remove::Benchmark::new();
188+
b.iter(move || bench.run());
189+
});
174190
}
175191

176192
fn bench_serialize_text(c: &mut Criterion) {

src/edict/add_remove.rs

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
use edict::prelude::*;
2+
3+
struct A(f32);
4+
struct B(f32);
5+
6+
pub struct Benchmark(World, Vec<Entity>);
7+
8+
impl Benchmark {
9+
pub fn new() -> Self {
10+
let mut world = World::new();
11+
12+
let entities = (0..10_000).map(|_| world.spawn((A(0.0),))).collect();
13+
14+
Self(world, entities)
15+
}
16+
17+
pub fn run(&mut self) {
18+
for entity in &self.1 {
19+
self.0.insert(entity, B(0.0));
20+
}
21+
22+
for entity in &self.1 {
23+
let _ = self.0.remove::<B>(entity);
24+
}
25+
}
26+
}

src/edict/frag_iter.rs

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
use edict::prelude::*;
2+
3+
macro_rules! create_entities {
4+
($world:ident; $entities:ident; $( $variants:ident ),*) => {
5+
$(
6+
struct $variants(f32);
7+
$entities.extend($world.spawn_batch((0..20).map(|_| ($variants(0.0), Data(1.0)))));
8+
)*
9+
};
10+
}
11+
12+
struct Data(f32);
13+
14+
pub struct Benchmark(World, Vec<Entity>);
15+
16+
impl Benchmark {
17+
pub fn new() -> Self {
18+
let mut world = World::default();
19+
let mut entities = Vec::new();
20+
21+
create_entities!(world; entities; A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z);
22+
23+
Self(world, entities)
24+
}
25+
26+
pub fn run(&mut self) {
27+
self.0.for_each_mut::<&mut Data, _>(|data| data.0 *= 2.0);
28+
}
29+
}

src/edict/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
pub mod add_remove;
2+
pub mod frag_iter;
3+
pub mod simple_insert;
4+
pub mod simple_iter;

src/edict/simple_insert.rs

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
use cgmath::*;
2+
use edict::prelude::*;
3+
4+
#[derive(Copy, Clone)]
5+
struct Transform(Matrix4<f32>);
6+
7+
#[derive(Copy, Clone)]
8+
struct Position(Vector3<f32>);
9+
10+
#[derive(Copy, Clone)]
11+
struct Rotation(Vector3<f32>);
12+
13+
#[derive(Copy, Clone)]
14+
struct Velocity(Vector3<f32>);
15+
16+
pub struct Benchmark {
17+
entities: Vec<Entity>,
18+
}
19+
20+
impl Benchmark {
21+
pub fn new() -> Self {
22+
Benchmark {
23+
entities: Vec::new(),
24+
}
25+
}
26+
27+
pub fn run(&mut self) {
28+
let mut world = World::new();
29+
30+
self.entities.extend(world.spawn_batch((0..10_000).map(|_| {
31+
(
32+
Transform(Matrix4::from_scale(1.0)),
33+
Position(Vector3::unit_x()),
34+
Rotation(Vector3::unit_x()),
35+
Velocity(Vector3::unit_x()),
36+
)
37+
})));
38+
}
39+
}

src/edict/simple_iter.rs

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
use cgmath::*;
2+
use edict::prelude::*;
3+
4+
#[derive(Copy, Clone)]
5+
struct Transform(Matrix4<f32>);
6+
7+
#[derive(Copy, Clone)]
8+
struct Position(Vector3<f32>);
9+
10+
#[derive(Copy, Clone)]
11+
struct Rotation(Vector3<f32>);
12+
13+
#[derive(Copy, Clone)]
14+
struct Velocity(Vector3<f32>);
15+
16+
pub struct Benchmark(World, Vec<Entity>);
17+
18+
impl Benchmark {
19+
pub fn new() -> Self {
20+
let mut world = World::new();
21+
let entities = world
22+
.spawn_batch((0..10_000).map(|_| {
23+
(
24+
Transform(Matrix4::from_scale(1.0)),
25+
Position(Vector3::unit_x()),
26+
Rotation(Vector3::unit_x()),
27+
Velocity(Vector3::unit_x()),
28+
)
29+
}))
30+
.collect();
31+
32+
Self(world, entities)
33+
}
34+
35+
pub fn run(&mut self) {
36+
self.0
37+
.for_each_mut::<(&Velocity, &mut Position), _>(|(velocity, position)| {
38+
position.0 += velocity.0;
39+
})
40+
}
41+
}

src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ pub mod legion_packed;
77
pub mod planck_ecs;
88
pub mod shipyard;
99
pub mod specs;
10+
pub mod edict;

0 commit comments

Comments
 (0)