blob: 577e44d4fe4b222eef95892d45a307c906c4132d (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
use criterion::{Criterion, Throughput, criterion_group, criterion_main};
use pish::parse::{
Parse,
regex::{Pattern, bc::BytecodeCompiledRegex},
};
/// https://mattmahoney.net/dc/enwik8.zip
pub fn regex_throughput(c: &mut Criterion) {
let mut content = std::fs::read("enwik8").unwrap();
content.truncate(1_000_000);
let mut group = c.benchmark_group("regex");
group.throughput(Throughput::Bytes(content.len() as u64));
let mut re = |re: &str| {
let pat = Pattern::parse_from_bytes(re.as_bytes()).unwrap();
let compiled = BytecodeCompiledRegex::try_from(pat).unwrap();
group.bench_function(&format!("enwik6 {re}"), |b| {
b.iter(|| {
let _ = compiled.re_match(&content);
})
});
};
re(".*");
re(".*(GNU)?.plus.(Linux)?.*");
re(".*GNU.plus.Linux.*");
group.finish();
}
criterion_group!(benches, regex_throughput);
criterion_main!(benches);
|