Skip to content

Commit

Permalink
better benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
untitaker committed Feb 9, 2022
1 parent d3d1270 commit 8f46fbb
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 16 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ version = "0.4.0"
include = ["src/**/*", "LICENSE", "README.md", "benches"]

[dev-dependencies]
criterion = "0.3.5"
pretty_assertions = "1.0.0"
serde = { version = "1.0.130", features = ["derive"] }
serde_json = "1.0.71"
test-generator = "0.3.0"
serde_bytes = "0.11.5"
glob = "0.3.0"
libtest-mimic = "0.3.0"
iai = "0.1.1"

[features]
# By default this crate depends on the jetscii library for best performance.
Expand All @@ -35,7 +35,7 @@ integration-tests = []
jetscii = { version = "0.5.1", optional = true }

[[bench]]
name = "data_state"
name = "patterns"
harness = false

[[test]]
Expand Down
14 changes: 0 additions & 14 deletions benches/data_state.rs

This file was deleted.

31 changes: 31 additions & 0 deletions benches/patterns.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use iai::{black_box, main};

use html5gum::Tokenizer;

fn pattern(pattern: &str, i: usize) {
let s: String = black_box((0..i).map(|_| pattern).collect());
for _ in Tokenizer::new(&s).infallible() {}
}

macro_rules! pattern_tests {
($(($name:ident, $pattern:expr, $repeat:expr), )*) => {
$(
fn $name() {
pattern($pattern, $repeat)
}
)*

main!($($name),*);
}
}

pattern_tests![
(data_state_10, "a", 10),
(data_state_10000, "a", 10000),
(tagopen_10, "<a>", 10),
(tagopen_10000, "<a>", 10000),
(tagopenclose_10, "<a></a>", 10),
(tagopenclose_10000, "<a></a>", 10000),
(comment_10, "<!-- -->", 10),
(comment_10000, "<!-- -->", 10000),
];

0 comments on commit 8f46fbb

Please sign in to comment.