//! Benchmarks for queue_index //! //! Compares Rust implementation against theoretical Go/C++ performance use criterion::{black_box, criterion_group, criterion_main, Criterion, BatchSize}; use queue_index::{QueueIndex, Task}; use tempfile::TempDir; fn bench_add_tasks(c: &mut Criterion) { c.bench_function("rust_queue_add_100", |b| { b.iter_batched( || { let temp = TempDir::new().unwrap(); QueueIndex::open(temp.path()).unwrap() }, |mut index| { let tasks: Vec = (0..100) .map(|i| Task::new(&format!("task-{}", i), "bench-job")) .collect(); black_box(index.add_tasks(&tasks).unwrap()); }, BatchSize::SmallInput, ); }); } fn bench_get_next_batch(c: &mut Criterion) { c.bench_function("rust_queue_get_10", |b| { let temp = TempDir::new().unwrap(); let mut index = QueueIndex::open(temp.path()).unwrap(); // Pre-populate with 1000 tasks let tasks: Vec = (0..1000) .map(|i| Task::new(&format!("task-{}", i), "bench-job")) .collect(); index.add_tasks(&tasks).unwrap(); b.iter(|| { black_box(index.get_next_batch(10).unwrap()); }); }); } fn bench_priority_ordering(c: &mut Criterion) { c.bench_function("rust_queue_priority", |b| { b.iter_batched( || { let temp = TempDir::new().unwrap(); let mut index = QueueIndex::open(temp.path()).unwrap(); // Add tasks with varying priorities let mut low = Task::new("low", "job"); low.priority = 10; let mut high = Task::new("high", "job"); high.priority = 100; let mut medium = Task::new("medium", "job"); medium.priority = 50; index.add_tasks(&[low, high, medium]).unwrap(); index }, |mut index| { black_box(index.get_next_batch(3).unwrap()); }, BatchSize::SmallInput, ); }); } criterion_group!(benches, bench_add_tasks, bench_get_next_batch, bench_priority_ordering); criterion_main!(benches);