Skip to content

Commit

Permalink
Merge #583
Browse files Browse the repository at this point in the history
583: Big VS Small component benchmarks. r=torkleyy a=jojolepro

## Checklist

* [X] I've added tests for all code changes and additions (where applicable)

## API changes
N/A



Co-authored-by: Joël Lupien (Jojolepro) <[email protected]>
  • Loading branch information
bors[bot] and AnneKitsune committed May 3, 2019
2 parents 23c85ec + 70efd14 commit f4c8ab1
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 3 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,6 @@ rand = "0.6.1"
serde_json = "1.0"
specs-derive = { path = "specs-derive", version = "0.4.0" }

[[example]]
name = "async"

[[example]]
name = "basic"

Expand Down Expand Up @@ -89,5 +86,8 @@ name = "parallel"
name = "world"
harness = false

[[bench]]
name = "big_or_small"

[workspace]
members = ["specs-derive"]
112 changes: 112 additions & 0 deletions benches/big_or_small.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
#![feature(test)]

extern crate cgmath;
extern crate rand;
extern crate shred;
extern crate specs;
extern crate test;

use cgmath::Vector3;
use specs::prelude::*;
use test::Bencher;

type Vec3 = Vector3<f32>;

// -- Components --
#[derive(Clone, Debug)]
struct Small(Vec3, Vec3);

impl Component for Small {
type Storage = VecStorage<Self>;
}

#[derive(Clone, Debug)]
struct Small2(Vec3, Vec3);

impl Component for Small2 {
type Storage = VecStorage<Self>;
}

#[derive(Clone, Debug)]
struct Big(Vec3, Vec3, Vec3, Vec3);

impl Component for Big {
type Storage = VecStorage<Self>;
}

// -- Systems --

struct SmallSystem;

impl<'a> System<'a> for SmallSystem {
type SystemData = (
ReadStorage<'a, Small>,
WriteStorage<'a, Small2>,
);

fn run(&mut self, (small, mut small2): Self::SystemData) {
for (s, mut s2) in (&small, &mut small2).join() {
s2.0.y += s.0.x;
}
}
}

struct BigSystem;

impl<'a> System<'a> for BigSystem {
type SystemData = (
WriteStorage<'a, Big>,
);

fn run(&mut self, (mut big,): Self::SystemData) {
for (mut b,) in (&mut big,).join() {
b.0.y += b.0.x;
}
}
}

#[bench]
fn bench_big(b: &mut Bencher) {
let mut world = World::new();

world.register::<Big>();

for _ in 0..100000 {
world.create_entity()
.with(Big(Vec3::new(0.0, 0.0, 0.0), Vec3::new(0.0, 0.0, 0.0), Vec3::new(0.0, 0.0, 0.0), Vec3::new(0.0, 0.0, 0.0)))
.build();
}

let mut dispatch = DispatcherBuilder::new()
.with(BigSystem, "big_sys", &[])
.build();

b.iter(|| {
dispatch.dispatch(&mut world);
world.maintain();
})
}

#[bench]
fn bench_small(b: &mut Bencher) {
let mut world = World::new();

world.register::<Small>();
world.register::<Small2>();

for _ in 0..100000 {
world.create_entity()
.with(Small(Vec3::new(0.0, 0.0, 0.0), Vec3::new(0.0, 0.0, 0.0)))
.with(Small2(Vec3::new(0.0, 0.0, 0.0), Vec3::new(0.0, 0.0, 0.0)))
.build();
}

let mut dispatch = DispatcherBuilder::new()
.with(SmallSystem, "small_sys", &[])
.build();

b.iter(|| {
dispatch.dispatch(&mut world);
world.maintain();
})
}

0 comments on commit f4c8ab1

Please sign in to comment.