bheisler / criterion.rs

Statistics-driven benchmarking library for Rust
Apache License 2.0
4.28k stars 290 forks source link

panic in drop #756

Open rbtcollins opened 5 months ago

rbtcollins commented 5 months ago

Getting this:

 16:     0x562eb027aaf3 - core::result::unwrap_failed::hddb4fea594200c52
                               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/result.rs:1653:5
  17:     0x562eb0290a0d - <criterion::benchmark_group::BenchmarkGroup<M> as core::ops::drop::Drop>::drop::he08f359ac432fea0
  18:     0x562eb02a2fe1 - core::ptr::drop_in_place<criterion::benchmark_group::BenchmarkGroup<criterion::measurement::WallTime>>::h6738354a2f13e3af
  19:     0x562eb02a64aa - routelookups::main::he1be34487cdda972

Presumably I'm doing something strange, but its not obvious what it is :)

benchmark code looks something like:

pub fn criterion_benchmark(c: &mut Criterion) {

    let die = Uniform::from(0..10);
    let mut cases = vec![];

    for scale in [
        1, 10, 100, 1_000, 10_000, 100_000, 1_000_000, 
    ] {
        // ... create a data structure of that scale
        let table = ...
        let paths = Vec::from([...])
        cases.push((scale, paths, table));
    }

    let mut group = c.benchmark_group("lookups");
    for (size, paths, table) in cases.iter() {
        let mut paths = paths.iter().cycle();
        group.throughput(Throughput::Elements(*size as u64));
        if *size > 100_000 {
            group.measurement_time(Duration::from_secs(10));
        }
        group.bench_with_input(
            BenchmarkId::from_parameter(format!("{REPS}_lookups_in_{size}_table")),
            size,
            |b, &_size| {
                b.iter(|| {
                    // REPS lookups in each datastructure
                    for _ in 0..REPS {
                        lookup_route(black_box(table), black_box(paths.next().unwrap()));
                    }
                })
            },
        );
    }
    group.finish();
}

criterion_group!(benches, criterion_benchmark);
criterion_main!(benches);