use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion, Throughput}; use toolchain::lexer; /// "Speed of light" benchmarking. Intended to capture the absolute fastest throughput a /// byte-for-byte analysis of an input string is likely to be able to achieve. This gives the /// other benchmarks a reference comparison for the limiting factors on a given hardware platform. pub fn string_validation(c: &mut Criterion) { let mut group = c.benchmark_group("validate_utf8"); for size in [1024, 2 * 1024, 4 * 1024, 8 * 1024, 16 * 1024].iter() { group.throughput(Throughput::Bytes(*size as u64)); group.bench_with_input(BenchmarkId::from_parameter(size), size, |b, &size| { let mut s = String::new(); while s.len() < size { s.push_str("abcdefghijklmnopqrstuvwxyz012345"); } b.iter(|| { lexer::validate_utf8(black_box(s.as_bytes())); }); }); } group.finish(); } criterion_group!(speed_of_light, string_validation); criterion_main!(speed_of_light);