diff options
| author | Jonas Maier <jonas@x77.dev> | 2026-06-06 10:41:52 +0200 |
|---|---|---|
| committer | Jonas Maier <jonas@x77.dev> | 2026-06-06 10:41:52 +0200 |
| commit | 75e0c29cf91ddc6299c14a94a038c3e3df3d2805 (patch) | |
| tree | f2c64e63a657333bc946af8918a81f345c495665 | |
| parent | 1ff733a821a947880baaad42aab43a398285418c (diff) | |
| download | pish-75e0c29cf91ddc6299c14a94a038c3e3df3d2805.tar.gz | |
regex: throughput in benchmark
| -rw-r--r-- | benches/regex.rs | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/benches/regex.rs b/benches/regex.rs index 7f20606..577e44d 100644 --- a/benches/regex.rs +++ b/benches/regex.rs @@ -1,4 +1,4 @@ -use criterion::{Criterion, criterion_group, criterion_main}; +use criterion::{Criterion, Throughput, criterion_group, criterion_main}; use pish::parse::{ Parse, regex::{Pattern, bc::BytecodeCompiledRegex}, @@ -8,14 +8,26 @@ use pish::parse::{ pub fn regex_throughput(c: &mut Criterion) { let mut content = std::fs::read("enwik8").unwrap(); content.truncate(1_000_000); - let pat = Pattern::parse_from_bytes(b".*GNU.plus.Linux.*").unwrap(); - let compiled = BytecodeCompiledRegex::try_from(pat).unwrap(); - c.bench_function("enwik8 match-all", |b| { - b.iter(|| { - let _ = compiled.re_match(&content); - }) - }); + 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); |
