From f0a4f8b0f6e9f0121237d19ad3e5ef75a206084c Mon Sep 17 00:00:00 2001 From: Adrien Burgun Date: Fri, 24 Jun 2022 11:37:57 +0200 Subject: [PATCH] :chart: Add benchmark for Pane::step --- stackline/Cargo.toml | 5 +++++ stackline/benches/dispatch.rs | 29 +++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 stackline/benches/dispatch.rs diff --git a/stackline/Cargo.toml b/stackline/Cargo.toml index 639b1f9..a0fab18 100755 --- a/stackline/Cargo.toml +++ b/stackline/Cargo.toml @@ -11,3 +11,8 @@ palette = "0.6" [dev-dependencies] colored = "2.0" +criterion = { version = "0.3.5", features = ["html_reports"] } + +[[bench]] +name = "dispatch" +harness = false diff --git a/stackline/benches/dispatch.rs b/stackline/benches/dispatch.rs new file mode 100644 index 0000000..2a924ae --- /dev/null +++ b/stackline/benches/dispatch.rs @@ -0,0 +1,29 @@ +use criterion::{black_box, criterion_group, criterion_main, Criterion}; +use stackline::prelude::*; +use stackline::tile::*; + +fn benchmark_step(c: &mut Criterion) { + c.bench_function("Pane::step", |b| { + let mut pane = Pane::empty(3, 3).unwrap(); + + pane.set_tile((0, 0), Diode::new(Direction::Right)); + pane.set_tile((2, 0), Diode::new(Direction::Down)); + pane.set_tile((2, 2), Diode::new(Direction::Left)); + pane.set_tile((0, 2), Diode::new(Direction::Up)); + pane.set_tile((1, 0), Wire::new(Orientation::Horizontal)); + pane.set_tile((1, 2), Wire::new(Orientation::Horizontal)); + pane.set_tile((0, 1), Wire::new(Orientation::Vertical)); + pane.set_tile((2, 1), Wire::new(Orientation::Vertical)); + + pane.set_signal((0, 0), stackline::signal!( + (0, 0), + Direction::Right, + [] + )); + + b.iter(|| pane.step()); + }); +} + +criterion_group!(benches, benchmark_step); +criterion_main!(benches);