aboutsummaryrefslogtreecommitdiffstats
path: root/benches/regex.rs
blob: dd8f54a3a04226d40ae1cea81b04b4bc5f6b217d (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
use criterion::{Criterion, Throughput, criterion_group, criterion_main};
use pish::parse::Parse;
use pish::regex::{Pattern, RegexEngine};

/// 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 = pat.try_compile().unwrap();

        group.bench_function(&format!("enwik6 {re}"), |b| {
            b.iter(|| {
                compiled.matches(&content);
            })
        });
    };

    re(".*");
    re(".*(GNU)?.plus.(Linux)?.*");
    re(".*GNU.plus.Linux.*");

    group.finish();
}

criterion_group!(benches, regex_throughput);
criterion_main!(benches);