25 releases
Uses new Rust 2024
| 0.2.22 | Nov 15, 2025 |
|---|---|
| 0.2.21 | Nov 10, 2025 |
| 0.2.18 | Oct 27, 2025 |
| 0.2.17 | Sep 22, 2025 |
| 0.1.1 | Jul 24, 2025 |
#146 in Profiling
565KB
9K
SLoC
Mechanisms for multithreaded benchmarking, designed for integration with Criterion or a similar benchmark framework.
This package provides low-overhead utilities for benchmarking operations across multiple threads, with features like thread pool reuse, flexible configuration, and seamless integration with popular benchmark frameworks.
use std::hint::black_box;
use std::sync::Arc;
use std::sync::atomic::{AtomicU64, Ordering};
use par_bench::{Run, ThreadPool};
// Create a thread pool.
let pool = ThreadPool::default();
// Shared atomic counter that all threads will increment.
let counter = Arc::new(AtomicU64::new(0));
let run = Run::new()
.prepare_thread_fn({
let counter = Arc::clone(&counter);
move |_run_meta| Arc::clone(&counter)
})
.prepare_iter_fn(|_run_meta, counter| Arc::clone(counter))
.iter_fn(|counter: Arc<AtomicU64>| {
// Increment the atomic counter and use black_box to prevent optimization.
black_box(counter.fetch_add(1, Ordering::Relaxed));
});
// Execute 10,000 iterations across all threads.
let stats = run.execute_on(&pool, 10_000);
// Get the mean duration for benchmark reporting.
let duration = stats.mean_duration();
More details in the package documentation.
This is part of the Folo project that provides mechanisms for high-performance hardware-aware programming in Rust.
Dependencies
~3–24MB
~391K SLoC