Skip to content

Commit 6a1e92f

Browse files
Akida31untitaker
authored andcommitted
add file benches
This adds some "real world" benchmarks, which are taken from https://github.com/AndreasMadsen/htmlparser-benchmark/tree/master/files.
1 parent 60f5f80 commit 6a1e92f

File tree

4 files changed

+3171
-0
lines changed

4 files changed

+3171
-0
lines changed

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ jetscii = { version = "0.5.1", optional = true }
4545
name = "patterns"
4646
harness = false
4747

48+
[[bench]]
49+
name = "files"
50+
harness = false
51+
4852
[[test]]
4953
name = "html5lib-tokenizer"
5054
path = "tests/html5lib_tokenizer.rs"

benches/files.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#![allow(non_snake_case)]
2+
use iai::{black_box, main};
3+
4+
use html5gum::Tokenizer;
5+
6+
// files taken from https://github.com/AndreasMadsen/htmlparser-benchmark/tree/master/files
7+
const F0050: &str = include_str!("files/0050.html");
8+
const F6D30: &str = include_str!("files/6D30.html");
9+
10+
fn file(file: &str, i: usize) {
11+
let s: String = black_box((0..i).map(|_| file).collect());
12+
for Ok(_) in Tokenizer::new(&s) {}
13+
}
14+
15+
macro_rules! pattern_tests {
16+
($(($name:ident, $file:expr, $repeat:expr), )*) => {
17+
$(
18+
fn $name() {
19+
file($file, $repeat)
20+
}
21+
)*
22+
23+
main!($($name),*);
24+
}
25+
}
26+
27+
pattern_tests![
28+
(file_0050_10, F0050, 10),
29+
(file_0050_100, F0050, 100),
30+
(file_6D30_10, F6D30, 10),
31+
(file_6D30_100, F6D30, 100),
32+
];

0 commit comments

Comments
 (0)