| Crates.io | par_bench |
| lib.rs | par_bench |
| version | 0.2.28 |
| created_at | 2025-07-24 05:43:10.029769+00 |
| updated_at | 2026-01-08 04:34:57.271742+00 |
| description | Mechanisms for multithreaded benchmarking, designed for integration with Criterion or a similar benchmark framework |
| homepage | |
| repository | https://github.com/folo-rs/folo |
| max_upload_size | |
| id | 1765552 |
| size | 180,446 |
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::sync::atomic::{AtomicU64, Ordering};
use many_cpus::ProcessorSet;
use par_bench::{Run, ThreadPool};
// Create a thread pool with two processors.
let two_processors = ProcessorSet::builder()
.take(std::num::NonZero::new(2).unwrap())
.expect("need at least 2 processors for multi-threaded benchmarks");
let mut pool = ThreadPool::new(&two_processors);
// Shared atomic counter that all threads will increment.
let counter = AtomicU64::new(0);
// Execute 10,000 iterations across all threads.
let stats = Run::new()
.iter(|_| counter.fetch_add(1, Ordering::Relaxed))
.execute_on(&mut 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.