par_bench

Crates.iopar_bench
lib.rspar_bench
version0.2.13
created_at2025-07-24 05:43:10.029769+00
updated_at2025-08-28 08:26:40.294603+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
size172,592
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::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.

Commit count: 810

cargo fmt