#![allow(missing_docs, unused_results)]
use criterion::{BenchmarkId, Criterion, Throughput, criterion_group, criterion_main};
use serde::Deserialize;
use std::hint::black_box;
#[derive(Debug, Deserialize)]
#[allow(dead_code)]
struct Record {
id: u32,
kind: String,
payload: String,
}
fn build_stream(doc_count: usize, body_repeats: usize) -> String {
let mut s = String::with_capacity(doc_count * (48 + body_repeats * 24));
for i in 0..doc_count {
s.push_str(&format!("---\nid: {i}\nkind: audit\npayload: \""));
for j in 0..body_repeats {
s.push_str(&format!("field-{j}-{i} "));
}
s.push_str("\"\n");
}
s
}
fn bench_parallel(c: &mut Criterion) {
let mut group = c.benchmark_group("parallel_vs_sequential");
let shapes = [
("tiny_docs", 900usize, 0usize), ("medium_docs", 900, 24), ("large_docs", 300, 96), ];
for &(label, doc_count, body_repeats) in &shapes {
let stream = build_stream(doc_count, body_repeats);
group.throughput(Throughput::Bytes(stream.len() as u64));
group.bench_with_input(BenchmarkId::new("sequential", label), &stream, |b, y| {
b.iter(|| {
let v: Vec<Record> = noyalib::load_all_as(black_box(y)).unwrap();
black_box(v);
});
});
group.bench_with_input(BenchmarkId::new("parallel", label), &stream, |b, y| {
b.iter(|| {
let v: Vec<Record> = noyalib::parallel::parse(black_box(y)).unwrap();
black_box(v);
});
});
}
group.finish();
}
criterion_group!(benches, bench_parallel);
criterion_main!(benches);