#![allow(missing_docs)]
use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion};
use sashite_sin::Identifier;
const VALID: &[&str] = &["W", "c", "Z"];
const INVALID: &[&str] = &["", "WW", "1", "WWWW"];
fn parse_valid(c: &mut Criterion) {
let mut group = c.benchmark_group("parse_valid");
for &token in VALID {
group.bench_with_input(BenchmarkId::from_parameter(token), token, |b, t| {
b.iter(|| Identifier::parse(black_box(t)));
});
}
group.finish();
}
fn parse_invalid(c: &mut Criterion) {
let mut group = c.benchmark_group("parse_invalid");
for &token in INVALID {
let label = if token.is_empty() { "<empty>" } else { token };
group.bench_with_input(BenchmarkId::from_parameter(label), token, |b, t| {
b.iter(|| Identifier::parse(black_box(t)));
});
}
group.finish();
}
fn encode(c: &mut Criterion) {
let id = Identifier::parse("W").expect("valid token");
c.bench_function("encode", |b| {
b.iter(|| black_box(id).encode());
});
}
fn round_trip(c: &mut Criterion) {
c.bench_function("round_trip", |b| {
b.iter(|| Identifier::parse(black_box("W")).map(Identifier::encode));
});
}
criterion_group!(benches, parse_valid, parse_invalid, encode, round_trip);
criterion_main!(benches);