From 00ae858704f6bb742324b720964abe4ef0782470 Mon Sep 17 00:00:00 2001 From: j-mendez Date: Mon, 16 Oct 2023 22:14:41 -0400 Subject: [PATCH] bench(audit): add bench --- .github/workflows/bench.yml | 32 +++ Cargo.lock | 295 ++++++++++++++++++++++++++ Cargo.toml | 4 +- README.md | 10 + accessibility-rs/src/lib.rs | 2 +- accessibility-tree/victor/src/geom.rs | 30 +-- benches/Cargo.toml | 14 ++ benches/README.md | 13 ++ benches/audit.rs | 25 +++ benches/mock.rs | 4 + 10 files changed, 412 insertions(+), 17 deletions(-) create mode 100644 .github/workflows/bench.yml create mode 100644 benches/Cargo.toml create mode 100644 benches/README.md create mode 100644 benches/audit.rs create mode 100644 benches/mock.rs diff --git a/.github/workflows/bench.yml b/.github/workflows/bench.yml new file mode 100644 index 0000000..b873b27 --- /dev/null +++ b/.github/workflows/bench.yml @@ -0,0 +1,32 @@ +name: Benches +on: + push: + branches: [main] + pull_request: + branches: [main] + +env: + CARGO_TERM_COLOR: always + RUST_LOG: "off" + +concurrency: + group: ${{ github.ref }} + cancel-in-progress: true + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/cache@v3 + id: cache + with: + path: | + ~/.cargo/bin/ + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + target/ + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + - name: Run Benchmark + run: cargo bench --bench audit \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index b5ee176..99a8561 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -64,6 +64,21 @@ dependencies = [ "xml-rs", ] +[[package]] +name = "addr2line" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + [[package]] name = "ahash" version = "0.8.3" @@ -138,6 +153,29 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +[[package]] +name = "backtrace" +version = "0.3.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2089b7e3f35b9dd2d0ed921ead4f6d318c27680d4a5bd167b3ee120edb105837" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] +name = "benches" +version = "0.0.0" +dependencies = [ + "accessibility-rs", + "criterion", +] + [[package]] name = "bitflags" version = "1.3.2" @@ -166,6 +204,21 @@ version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" +[[package]] +name = "cast" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" + +[[package]] +name = "cc" +version = "1.0.83" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0" +dependencies = [ + "libc", +] + [[package]] name = "cfg-if" version = "1.0.0" @@ -196,6 +249,44 @@ dependencies = [ "bitflags", ] +[[package]] +name = "criterion" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b01d6de93b2b6c65e17c634a26653a29d107b3c98c607c765bf38d041531cd8f" +dependencies = [ + "atty", + "cast", + "clap", + "criterion-plot", + "csv", + "futures", + "itertools", + "lazy_static", + "num-traits", + "oorandom", + "plotters", + "rayon", + "regex", + "serde", + "serde_cbor", + "serde_derive", + "serde_json", + "tinytemplate", + "tokio", + "walkdir", +] + +[[package]] +name = "criterion-plot" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2673cc8207403546f45f5fd319a974b1e6983ad1a3ee7e6041650013be041876" +dependencies = [ + "cast", + "itertools", +] + [[package]] name = "crossbeam-deque" version = "0.8.3" @@ -261,6 +352,27 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "csv" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac574ff4d437a7b5ad237ef331c17ccca63c46479e5b5453eb8e10bb99a759fe" +dependencies = [ + "csv-core", + "itoa 1.0.9", + "ryu", + "serde", +] + +[[package]] +name = "csv-core" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5efa2b3d7902f4b634a20cae3c9c4e6209dc4779feb6863329607560143efa70" +dependencies = [ + "memchr", +] + [[package]] name = "dtoa" version = "0.4.8" @@ -343,6 +455,67 @@ dependencies = [ "new_debug_unreachable", ] +[[package]] +name = "futures" +version = "0.3.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23342abe12aba583913b2e62f22225ff9c950774065e4bfb61a19cd9770fec40" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "955518d47e09b25bbebc7a18df10b81f0c766eaf4c4f1cccef2fca5f2a4fb5f2" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4bca583b7e26f571124fe5b7561d49cb2868d79116cfa0eefce955557c6fee8c" + +[[package]] +name = "futures-io" +version = "0.3.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fff74096e71ed47f8e023204cfd0aa1289cd54ae5430a9523be060cdb849964" + +[[package]] +name = "futures-sink" +version = "0.3.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f43be4fe21a13b9781a69afa4985b0f6ee0e1afab2c6f454a8cf30e2b2237b6e" + +[[package]] +name = "futures-task" +version = "0.3.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76d3d132be6c0e6aa1534069c705a74a5997a356c0dc2f86a47765e5617c5b65" + +[[package]] +name = "futures-util" +version = "0.3.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26b01e40b772d54cf6c6d721c1d1abd0647a0106a12ecaa1c186273392a69533" +dependencies = [ + "futures-core", + "futures-sink", + "futures-task", + "pin-project-lite", + "pin-utils", +] + [[package]] name = "fxhash" version = "0.2.1" @@ -374,6 +547,12 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "gimli" +version = "0.28.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fb8d784f27acf97159b40fc4db5ecd8aa23b9ad5ef69cdd136d3bc80665f0c0" + [[package]] name = "glob" version = "0.3.1" @@ -410,6 +589,12 @@ version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eec1c01eb1de97451ee0d60de7d81cf1e72aabefb021616027f3d1c3ec1c723c" +[[package]] +name = "half" +version = "1.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eabb4a44450da02c90444cf74558da904edde8fb4e9035a9a6a4e15445af0bd7" + [[package]] name = "hashbrown" version = "0.12.3" @@ -630,6 +815,15 @@ dependencies = [ "autocfg 1.1.0", ] +[[package]] +name = "miniz_oxide" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7810e0be55b428ada41041c41f32c9f1a42817901b4ccf45fa3d4b6561e74c7" +dependencies = [ + "adler", +] + [[package]] name = "moite_moite" version = "0.2.0" @@ -666,12 +860,27 @@ dependencies = [ "autocfg 1.1.0", ] +[[package]] +name = "object" +version = "0.32.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9cf5f9dd3933bd50a9e1f149ec995f39ae2c496d31fd772c1fd45ebc27e902b0" +dependencies = [ + "memchr", +] + [[package]] name = "once_cell" version = "1.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" +[[package]] +name = "oorandom" +version = "11.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ab1bc2a289d34bd04a330323ac98a1b4bc82c9d9fcb1e66b63caa84da26b575" + [[package]] name = "parking_lot" version = "0.12.1" @@ -771,6 +980,46 @@ dependencies = [ "siphasher 0.3.11", ] +[[package]] +name = "pin-project-lite" +version = "0.2.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "plotters" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2c224ba00d7cadd4d5c660deaf2098e5e80e07846537c51f9cfa4be50c1fd45" +dependencies = [ + "num-traits", + "plotters-backend", + "plotters-svg", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "plotters-backend" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e76628b4d3a7581389a35d5b6e2139607ad7c75b17aed325f210aa91f4a9609" + +[[package]] +name = "plotters-svg" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38f6d39893cca0701371e3c27294f09797214b86f1fb951b89ade8ec04e2abab" +dependencies = [ + "plotters-backend", +] + [[package]] name = "ppv-lite86" version = "0.2.17" @@ -1137,6 +1386,12 @@ dependencies = [ "toml", ] +[[package]] +name = "rustc-demangle" +version = "0.1.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" + [[package]] name = "rustversion" version = "1.0.14" @@ -1198,6 +1453,16 @@ dependencies = [ "serde_derive", ] +[[package]] +name = "serde_cbor" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2bef2ebfde456fb76bbcf9f59315333decc4fda0b2b44b420243c11e0f5ec1f5" +dependencies = [ + "half", + "serde", +] + [[package]] name = "serde_derive" version = "1.0.188" @@ -1431,6 +1696,26 @@ dependencies = [ "once_cell", ] +[[package]] +name = "tinytemplate" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be4d6b5f19ff7664e8c98d03e2139cb510db9b0a60b55f8e8709b689d939b6bc" +dependencies = [ + "serde", + "serde_json", +] + +[[package]] +name = "tokio" +version = "1.33.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4f38200e3ef7995e5ef13baec2f432a6da0aa9ac495b2c0e8f3b7eec2c92d653" +dependencies = [ + "backtrace", + "pin-project-lite", +] + [[package]] name = "toml" version = "0.7.8" @@ -1580,6 +1865,16 @@ version = "0.2.87" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ca6ad05a4870b2bf5fe995117d3728437bd27d7cd5f06f13c17443ef369775a1" +[[package]] +name = "web-sys" +version = "0.3.64" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b85cbef8c220a6abc02aefd892dfc0fc23afb1c6a426316ec33253a3877249b" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + [[package]] name = "winapi" version = "0.3.9" diff --git a/Cargo.toml b/Cargo.toml index 17816d1..cfba4ba 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,9 @@ resolver = "2" members = [ "accessibility-rs", "accessibility-tree/victor", - "accessibility-scraper" + "accessibility-scraper", + # internal + "benches" ] [workspace.dependencies] diff --git a/README.md b/README.md index 8d80a07..d2dd4d3 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,16 @@ To help improve the rules the following needs to be done: 1. [Wasm](https://webassembly.org/) example view [kayle_innate](https://github.com/a11ywatch/kayle/blob/main/kayle_innate/kayle_innate/src/lib.rs#L35). 1. Example integrating with a [headless browser](https://github.com/a11ywatch/kayle/blob/main/kayle/tests/innate.ts#L14). +## Benchmarks + +```sh +audit-speed/core/audit: audit speed (4k iterations) +time: [1.1475 ms 1.1507 ms 1.1531 ms] +``` + +Currently audits may take up to `1ms` at `stage 0`. We have goals set to drastically increase the performance after the each stage. Some of the stages are set to be done as the engine is built out. +For now as the audits may take up to `1ms` we are focusing on the rules until performance degrades. + ### License This project is licensed under either of diff --git a/accessibility-rs/src/lib.rs b/accessibility-rs/src/lib.rs index 1fafe6c..c1236e6 100644 --- a/accessibility-rs/src/lib.rs +++ b/accessibility-rs/src/lib.rs @@ -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> { diff --git a/accessibility-tree/victor/src/geom.rs b/accessibility-tree/victor/src/geom.rs index 5d5afd2..58d8a7a 100644 --- a/accessibility-tree/victor/src/geom.rs +++ b/accessibility-tree/victor/src/geom.rs @@ -25,21 +25,21 @@ pub mod physical { } impl Sides { - pub fn inner_px(&self) -> f32 { - let b = Self::get_px::(self.bottom); - let t = Self::get_px::(self.top); - let l = Self::get_px::(self.left); - let r = Self::get_px::(self.left); - - b + t + l + r - } - - pub fn get_px(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::(self.bottom); + // let t = Self::get_px::(self.top); + // let l = Self::get_px::(self.left); + // let r = Self::get_px::(self.left); + + // b + t + l + r + // } + + // pub fn get_px(v: LengthOrPercentage) -> f32 { + // match v { + // LengthOrPercentage::Length(l) => l.px, + // LengthOrPercentage::Percentage(l) => l.unit_value, + // } + // } } } diff --git a/benches/Cargo.toml b/benches/Cargo.toml new file mode 100644 index 0000000..0d93c99 --- /dev/null +++ b/benches/Cargo.toml @@ -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 \ No newline at end of file diff --git a/benches/README.md b/benches/README.md new file mode 100644 index 0000000..2a3e46c --- /dev/null +++ b/benches/README.md @@ -0,0 +1,13 @@ +# benchmarks + +Benchmarking the accessibility engine. + +## Stages + +The performance is set at stage 0 of 3 more details of the benchmark goals. Each stage should have drastic performance increases. + + +```sh +audit-speed/core/audit: audit speed (4k iterations) +time: [1.1475 ms 1.1507 ms 1.1531 ms] +``` \ No newline at end of file diff --git a/benches/audit.rs b/benches/audit.rs new file mode 100644 index 0000000..8c29294 --- /dev/null +++ b/benches/audit.rs @@ -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 = "medium-large html"; + + 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); diff --git a/benches/mock.rs b/benches/mock.rs new file mode 100644 index 0000000..69996b5 --- /dev/null +++ b/benches/mock.rs @@ -0,0 +1,4 @@ +/// mock website data from drake.com +pub static MOCK_WEBSITE_HTML: &'static str = r###" + Drake Industries | Custom, Durable, High-Quality Labels, Asset Tags and Custom Server Bezels
Main_BG_sm

SAME DAY QUOTES
INDUSTRY LEADING PRODUCT IDENTIFICATION

Drake has earned the trust of private industries, US, state & local governments and NASA.
REQUEST QUOTE

Welcome to Drake Industries

Product_Group_Img
Drake Industries is a manufacturer of high-quality, durable labels, nameplates, and ID tags for companies ranging from local restaurants… to PC builders… to NASA. Drake understands that you choose label solutions for your products, equipment and safety areas that incorporate durable materials, exacting production standards and, at times, very specialized designs. For more than 45 years, Drake has earned the trust of private industries, US, state & local governments and NASA.

Products

assetID-1
Labels
barcode-serial1
Nameplates
overlays-1
Equipment Panel Overlays
membraneswitch1
Membrane Switches
custom-badges
OEM Bezel Re-Branding
safetyhazard1
Safety

Capabilities

Drake Industries offers a full range of materials and print/manufacturing capabilities that support our durable label and marking solutions. We are capable of manufacturing a variety of labels and printing on a variety of materials and films. We are a UL® certified label manufacturer, and UL® and CSA® label printer in central Texas.
VIEW OUR LIST

About Drake

We are a manufacturer of high-quality, durable labels, dataplates, and ID tags. Drake understands that you choose label solutions for your products, equipment and safety areas that incorporate durable materials, exacting production standards and very specialized designs. For more than 45 years, Drake has earned the trust of private industries, US, state & local governments and NASA. We’re ready to earn your trust.
LEARN MORE

Request a Quote

Contact Drake to talk to an expert about your project.
GET A QUOTE
+"###; \ No newline at end of file