summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ecs/Cargo.toml2
-rw-r--r--ecs/benches/query.rs141
-rw-r--r--ecs/benches/query_iterating.rs119
3 files changed, 142 insertions, 120 deletions
diff --git a/ecs/Cargo.toml b/ecs/Cargo.toml
index 68d74f9..697db85 100644
--- a/ecs/Cargo.toml
+++ b/ecs/Cargo.toml
@@ -20,5 +20,5 @@ util-macros = { path = "../util-macros" }
criterion = "0.5.1"
[[bench]]
-name = "query_iterating"
+name = "query"
harness = false
diff --git a/ecs/benches/query.rs b/ecs/benches/query.rs
new file mode 100644
index 0000000..0f18f5c
--- /dev/null
+++ b/ecs/benches/query.rs
@@ -0,0 +1,141 @@
+use std::hint::black_box;
+use std::path::PathBuf;
+
+use criterion::{criterion_group, criterion_main, Criterion};
+use ecs::{Component, World};
+
+#[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 spawn_1000_entities(world: &mut World)
+{
+ 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(),
+ },
+ ));
+ }
+}
+
+fn benchbark(criterion: &mut Criterion)
+{
+ criterion.bench_function("Iterate 1000 entities", |bencher| {
+ let mut world = World::new();
+
+ spawn_1000_entities(&mut world);
+
+ let query = world.query::<(Bar, Position, Foo), ()>();
+
+ bencher.iter(|| {
+ for comps in query.iter() {
+ black_box(comps);
+ }
+ })
+ });
+}
+
+criterion_group!(benches, benchbark);
+criterion_main!(benches);
diff --git a/ecs/benches/query_iterating.rs b/ecs/benches/query_iterating.rs
deleted file mode 100644
index cfda4a3..0000000
--- a/ecs/benches/query_iterating.rs
+++ /dev/null
@@ -1,119 +0,0 @@
-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);