Skip to content

Commit

Permalink
bench(audit): add bench
Browse files Browse the repository at this point in the history
  • Loading branch information
j-mendez committed Oct 17, 2023
1 parent 4f52f0e commit 8c4ef71
Show file tree
Hide file tree
Showing 8 changed files with 364 additions and 17 deletions.
295 changes: 295 additions & 0 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ resolver = "2"
members = [
"accessibility-rs",
"accessibility-tree/victor",
"accessibility-scraper"
"accessibility-scraper",
# internal
"benches"
]

[workspace.dependencies]
Expand Down
2 changes: 1 addition & 1 deletion accessibility-rs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ pub struct AuditConfig<'a> {
/// the locale of the audit translations
pub locale: &'a str,
/// the guideline spec
pub spec: Conformance,
pub conformance: Conformance,
}

impl<'a> AuditConfig<'a> {
Expand Down
30 changes: 15 additions & 15 deletions accessibility-tree/victor/src/geom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,21 @@ pub mod physical {
}

impl Sides<LengthOrPercentage> {
pub fn inner_px(&self) -> f32 {
let b = Self::get_px::<LengthOrPercentage>(self.bottom);
let t = Self::get_px::<LengthOrPercentage>(self.top);
let l = Self::get_px::<LengthOrPercentage>(self.left);
let r = Self::get_px::<LengthOrPercentage>(self.left);

b + t + l + r
}

pub fn get_px<T>(v: LengthOrPercentage) -> f32 {
match v {
LengthOrPercentage::Length(l) => l.px,
LengthOrPercentage::Percentage(l) => l.unit_value,
}
}
// pub fn inner_px(&self) -> f32 {
// let b = Self::get_px::<LengthOrPercentage>(self.bottom);
// let t = Self::get_px::<LengthOrPercentage>(self.top);
// let l = Self::get_px::<LengthOrPercentage>(self.left);
// let r = Self::get_px::<LengthOrPercentage>(self.left);

// b + t + l + r
// }

// pub fn get_px<T>(v: LengthOrPercentage) -> f32 {
// match v {
// LengthOrPercentage::Length(l) => l.px,
// LengthOrPercentage::Percentage(l) => l.unit_value,
// }
// }
}
}

Expand Down
14 changes: 14 additions & 0 deletions benches/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[package]
name = "benches"
version = "0.0.0"
publish = false
edition = "2021"

[dependencies]
criterion = { version = "0.3.6", features = ["html_reports", "async_tokio"] }
accessibility-rs = { path = "../accessibility-rs" }

[[bench]]
name = "audit"
path = "audit.rs"
harness = false
7 changes: 7 additions & 0 deletions benches/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# benchmarks

Benchmarking the accessibility engine.

## Stages

The performance is set at stage 0 of 3 more details of the benchmark goals.
25 changes: 25 additions & 0 deletions benches/audit.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use accessibility_rs::{audit, AuditConfig};
use criterion::{black_box, criterion_group, criterion_main, Criterion};
mod mock;

/// bench audit speed
pub fn bench_speed(c: &mut Criterion) {
let mut group = c.benchmark_group("audit-speed/core");
let sample_count = 10;
let sample_title = "audit speed";

group.sample_size(sample_count);

group.bench_function(format!("audit: {}", sample_title), |b| {
b.iter(|| {
black_box(
audit(AuditConfig::basic(mock::MOCK_WEBSITE_HTML)),
)
})
});

group.finish();
}

criterion_group!(benches, bench_speed);
criterion_main!(benches);
4 changes: 4 additions & 0 deletions benches/mock.rs

Large diffs are not rendered by default.

0 comments on commit 8c4ef71

Please sign in to comment.