|
| 1 | +#![allow(missing_docs)] |
| 2 | +//! Benchmark: reserve() scaling with footprint size and number of reserved rewrites |
| 3 | +//! |
| 4 | +//! Measures how reserve() performance scales with: |
| 5 | +//! 1. Number of previously reserved rewrites (k) |
| 6 | +//! 2. Size of footprint being reserved (m) |
| 7 | +//! |
| 8 | +//! The current GenSet-based implementation should scale as O(m), independent of k. |
| 9 | +//! A naive Vec<Footprint> implementation would scale as O(k × m). |
| 10 | +
|
| 11 | +use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion, Throughput}; |
| 12 | +use rmg_core::Hash; |
| 13 | +use std::time::Duration; |
| 14 | + |
| 15 | +// Import the scheduler - it's crate-private so we can't access it directly |
| 16 | +// Instead we'll use it through the Engine API |
| 17 | +// Actually, we need direct access for this micro-benchmark, so we'll create |
| 18 | +// a test module inside rmg-core and expose it via a feature flag or just |
| 19 | +// write an integration test instead. |
| 20 | + |
| 21 | +// For now, let's write a simpler benchmark that measures reserve through the Engine API |
| 22 | + |
| 23 | +fn make_hash(val: u8) -> Hash { |
| 24 | + let mut h = [0u8; 32]; |
| 25 | + h[0] = val; |
| 26 | + h |
| 27 | +} |
| 28 | + |
| 29 | +// Note: This benchmark requires access to DeterministicScheduler which is crate-private. |
| 30 | +// Moving this to rmg-core/src/scheduler.rs tests module or using a pub(crate) test harness. |
| 31 | + |
| 32 | +fn bench_reserve_scaling(_c: &mut Criterion) { |
| 33 | + // This is a placeholder - the actual benchmark needs to be in rmg-core |
| 34 | + // where we can access the scheduler directly. |
| 35 | + |
| 36 | + // TODO: Implement this properly by either: |
| 37 | + // 1. Adding a test-only public API to DeterministicScheduler |
| 38 | + // 2. Moving this benchmark into rmg-core as a test module |
| 39 | + // 3. Using Engine API indirectly (less precise) |
| 40 | + |
| 41 | + let _ = ( |
| 42 | + BenchmarkId::new("placeholder", "reserve_scaling"), |
| 43 | + Throughput::Elements(1), |
| 44 | + make_hash(0), |
| 45 | + ); |
| 46 | +} |
| 47 | + |
| 48 | +criterion_group! { |
| 49 | + name = benches; |
| 50 | + config = Criterion::default() |
| 51 | + .warm_up_time(Duration::from_secs(1)) |
| 52 | + .measurement_time(Duration::from_secs(5)) |
| 53 | + .sample_size(50); |
| 54 | + targets = bench_reserve_scaling |
| 55 | +} |
| 56 | +criterion_main!(benches); |
0 commit comments