par_bench

Crates.iopar_bench
lib.rspar_bench
version0.2.28
created_at2025-07-24 05:43:10.029769+00
updated_at2026-01-08 04:34:57.271742+00
descriptionMechanisms for multithreaded benchmarking, designed for integration with Criterion or a similar benchmark framework
homepage
repositoryhttps://github.com/folo-rs/folo
max_upload_size
id1765552
size180,446
Sander Saares (sandersaares)

documentation

README

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();

See also

More details in the package documentation.

This is part of the Folo project that provides mechanisms for high-performance hardware-aware programming in Rust.

Commit count: 810

cargo fmt