bheisler / criterion.rs

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

Can I limit number of threads to use in benchmark? #782

Closed Crispy13 closed 1 month ago

Crispy13 commented 1 month ago

It seems that criterion uses all threads available.

Can I limit it? I must use a part of resources in server.

Crispy13 commented 1 month ago

Solved it with a dummy funtion

fn set_thread_pool(c: &mut Criterion) {
    static ONCE:Once  = Once::new();
    ONCE.call_once(|| 
        rayon::ThreadPoolBuilder::new().num_threads(4).build().unwrap()
    );
}

criterion_group!(benches, set_thread_pool, ...)
...