Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rust refactor (Part 1) #246

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
11 changes: 8 additions & 3 deletions crate/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "sandtable"
version = "0.1.0"
authors = ["maxbittker"]
edition = "2021"

[lib]
crate-type = ["cdylib", "rlib"]
Expand All @@ -10,9 +11,8 @@ crate-type = ["cdylib", "rlib"]
default = ["console_error_panic_hook"]

[dependencies]
cfg-if = "0.1.7"
cfg-if = "1.0.0"
wasm-bindgen = "0.2.42"
js-sys = "0.3.19"
rand = "0.8.3"
rand_xoshiro = "0.6.0"

Expand All @@ -23,7 +23,12 @@ rand_xoshiro = "0.6.0"
console_error_panic_hook = { version = "0.1.6", optional = true }

[dev-dependencies]
wasm-bindgen-test = "0.2"
wasm-bindgen-test = "0.3.33"
criterion = "0.4.0"

[[bench]]
name = "benchmarks"
harness = false

[profile.release]
# Tell `rustc` to optimize for small code size.
Expand Down
34 changes: 34 additions & 0 deletions crate/benches/benchmarks.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
use std::time::Duration;

use criterion::{criterion_group, criterion_main, Criterion};
use sandtable::{species::Species, universe::Universe};

fn setup_universe() -> Universe {
let n = 300;
let h = n / 2;
let d = n / 10 * 9;

let mut universe = Universe::new(n, n);

universe.paint(10, 10, 10, Species::Sand);
universe.paint(h, h, d + 2, Species::Plant);
universe.paint(30, n - 10, 15, Species::Fire);
universe.paint(h - 30, n - 10, 15, Species::Fire);
universe.paint(h, h, n / 3, Species::Empty);
universe.paint(h, h, n / 3, Species::Fire);

universe
}

fn universe_benchmark(c: &mut Criterion) {
let mut group = c.benchmark_group("Universe");
group.measurement_time(Duration::from_secs(10));

group.bench_function("universe::tick", |b| {
let mut universe = setup_universe();
b.iter(|| universe.tick())
});
}

criterion_group!(benches, universe_benchmark);
criterion_main!(benches);
Loading