Expand description
§FluxBench
Benchmarking framework for Rust with crash isolation, statistical rigor, and CI integration.
FluxBench provides a next-generation benchmarking platform:
- Process Isolation: Crash-resilient “Fail-Late” architecture; panicking benchmarks don’t crash the suite
- Binary IPC: Supervisor-worker messages use length-prefixed rkyv frames
- Statistical Rigor: Bootstrap resampling with BCa (bias-corrected and accelerated) confidence intervals
- CI Integration: Severity levels (critical/warning/info), GitHub Actions summaries, baseline comparison
- Algebraic Verification: Performance assertions directly in code with mathematical expressions
- Synthetic Metrics: Compute derived metrics from benchmark results
- Multi-Way Comparisons: Generate comparison tables and series charts
- Allocation Tracking:
TrackingAllocatormeasures heap usage per iteration - Timing:
Instantper timed region with timer overhead subtracted. Cycle counts use RDTSCP (x86_64) or CNTVCT_EL0 (aarch64), else 0
§Quick Start
use fluxbench::prelude::*;
#[flux::bench]
fn my_benchmark(b: &mut Bencher) {
b.iter(|| {
// Code to benchmark
expensive_operation()
});
}§Setup and Batching
iter_batched builds inputs untimed and hands each one to the routine by value.
iter_batched_ref hands a &mut input instead. BatchSize sets the inputs per timed batch.
#[flux::bench]
fn sort_fresh(b: &mut Bencher) {
b.iter_batched(
|| (0..1_000u32).rev().collect::<Vec<_>>(),
|mut v| { v.sort(); v },
BatchSize::SmallInput,
);
}
#[flux::bench]
fn clear_in_place(b: &mut Bencher) {
b.iter_batched_ref(|| vec![0u8; 4096], |v| v.fill(1), BatchSize::LargeInput);
}iter_custom lets the body time iters calls itself:
#[flux::bench]
fn self_timed(b: &mut Bencher) {
b.iter_custom(|iters| {
let start = std::time::Instant::now();
for _ in 0..iters {
std::hint::black_box(2 + 2);
}
start.elapsed()
});
}§Throughput
Set the work per call. Reports show bytes per second (binary units) or elements per second.
#[flux::bench(throughput_bytes = 4096)]
fn checksum_4k(b: &mut Bencher) {
let data = vec![1u8; 4096];
b.iter(|| data.iter().map(|&x| x as u64).sum::<u64>());
}
#[flux::bench]
fn parse_lines(b: &mut Bencher) {
let lines: Vec<String> = (0..100).map(|i| i.to_string()).collect();
b.throughput(Throughput::Elements(lines.len() as u64));
b.iter(|| lines.iter().filter_map(|l| l.parse::<u32>().ok()).sum::<u32>());
}§Group Config
A group sets run config for its benchmarks and child groups.
A #[flux::bench] attribute beats it. CLI flags and flux.toml lose to it.
#[flux::group(id = "io", sample_count = 30, measurement = "2s", warmup = "500ms")]
struct Io;§Async Benchmarks
The async feature (default) enables them.
iter_async times creating and awaiting each future.
The runtime builds once per benchmark. current_thread (the default) and multi_thread both work.
#[flux::bench(runtime = "multi_thread", worker_threads = 4)]
async fn async_benchmark(b: &mut Bencher) {
b.iter_async(|| async {
tokio::time::sleep(Duration::from_millis(1)).await;
});
}§Performance Assertions
#[flux::verify(expr = "(raw - overhead) < 50000000", severity = "critical")]
struct NetTimeCheck;Modules§
Structs§
- Bencher
- The Bencher provides iteration control for benchmarks.
- Benchmark
Def - Benchmark definition registered via
#[flux::bench] - Benchmark
Result - Result of a single benchmark run
- Bootstrap
Config - Bootstrap configuration
- Bootstrap
Result - Result of bootstrap analysis
- Chart
Def - Chart definition registered via
#[flux::chart]. - Compare
Def - Comparison group - groups multiple benchmarks for side-by-side comparison
- Group
Config - Run config a
#[flux::group]sets for every benchmark in it and in its child groups. - Group
Def - Group definition registered via
#[flux::group]. - Measure
Config - Config for one benchmark measurement.
- Metric
Context - Context holding benchmark metrics for expression evaluation
- Report
Def - Report definition registered via
#[flux::report]. - Summary
Statistics - Comprehensive summary statistics
- Synthetic
Def - Definition of a synthetic metric registered via
#[flux::synthetic] - Tracking
Allocator - Tracking allocator that wraps the system allocator
- Verification
- Verification definition
- Verification
Result - Result of a verification check
- Verify
Def - Definition of a verification rule registered via
#[flux::verify]
Enums§
- Batch
Size - Inputs per timed batch for
iter_batchedanditer_batched_ref. - Chart
Type - Chart kind for
#[flux::chart] - Iteration
Mode - Mode of iteration for the benchmark
- Measure
Error - Error from one benchmark measurement.
- Severity
- Severity levels for CI integration
- Throughput
- Work one routine call processes.
- Verification
Status - Verification execution status with explicit states for all outcomes.
Functions§
- compute_
bootstrap - Compute bootstrap confidence interval for the mean
- compute_
summary - Compute summary statistics from the raw samples.
- current_
allocation - Get current allocation statistics
- reset_
allocation_ counter - Reset allocation counters (call before each iteration)
- run
- Run the FluxBench CLI harness.
Attribute Macros§
- bench
- Register a benchmark function
- chart
- Add an SVG chart of one metric per benchmark to the HTML report
- compare
- Define a comparison group for multiple benchmarks
- group
- Describe a benchmark group
- report
- Set the HTML report title, description, and chart grid
- synthetic
- Define a synthetic (computed) metric
- verify
- Define a performance verification