-
Notifications
You must be signed in to change notification settings - Fork 220
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
2 changed files
with
115 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}) | ||
} |