add benchmark

This commit is contained in:
Magnus Ulimoen 2019-09-09 19:35:23 +02:00
parent 8a8e2fefec
commit bb5d7b1e38
2 changed files with 28 additions and 0 deletions

View File

@ -19,3 +19,11 @@ ndarray = "0.12.1"
[profile.release]
opt-level = 3
lto = "thin"
[dev-dependencies]
criterion = "0.3"
[[bench]]
name = "system"
path = "src/benches/bench.rs"
harness = false

20
src/benches/bench.rs Normal file
View File

@ -0,0 +1,20 @@
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use maxwell::Universe;
fn simple_system(w: u32, h: u32) -> Universe {
let mut universe = Universe::new(w, h);
universe.init(0.0, 0.0);
for _ in 0..100 {
universe.advance(0.01);
}
universe
}
fn performance_benchmark(c: &mut Criterion) {
c.bench_function("complete system", |b| {
b.iter(|| simple_system(black_box(25), black_box(30)))
});
}
criterion_group!(benches, performance_benchmark);
criterion_main!(benches);