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("(.*)");
    re("abc.............+");
    re(".*(GNU)?.plus.(Linux)?.*");
    re(".*GNU.*plus.*Linux.*");
    re(".*(0|1(01*0)*1)(0|1(01*0)*1)(0|1(01*0)*1)+.*");

    group.finish();
}

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