use std::hint::black_box;
use criterion::{Criterion, Throughput, criterion_group, criterion_main};
use yamd::deserialize;
const LONG_VALID_YAMD: &str = include_str!("./human_input.yamd");
const RANDOM_LOW_DENSITY: &str = include_str!("./random_token_low_density.yamd");
const RANDOM_HIGH_DENSITY: &str = include_str!("./random_token_high_density.yamd");
fn long_valid(c: &mut Criterion) {
let mut group = c.benchmark_group("throughput");
group.throughput(Throughput::Bytes(LONG_VALID_YAMD.len() as u64));
group.bench_function("~344kb of YAMD written by humman", |b| {
b.iter(|| deserialize(black_box(LONG_VALID_YAMD)))
});
group.finish();
}
fn random_long_lines(c: &mut Criterion) {
let mut group = c.benchmark_group("throughput");
group.throughput(Throughput::Bytes(RANDOM_LOW_DENSITY.len() as u64));
group.bench_function("~346kb with low density of tokens", |b| {
b.iter(|| deserialize(black_box(RANDOM_LOW_DENSITY)))
});
group.finish();
}
fn random_short_lines(c: &mut Criterion) {
let mut group = c.benchmark_group("throughput");
group.throughput(Throughput::Bytes(RANDOM_HIGH_DENSITY.len() as u64));
group.bench_function("~344kb with high density of tokens", |b| {
b.iter(|| deserialize(black_box(RANDOM_HIGH_DENSITY)))
});
group.finish();
}
criterion_group!(benches, long_valid, random_short_lines, random_long_lines);
criterion_main!(benches);