Expand description
§cntryl-stress
A lightweight single-shot benchmark runner for system-level stress tests.
Unlike Criterion (which uses statistical sampling), this crate is designed for expensive operations where each iteration matters: disk I/O, network calls, database transactions, compaction, recovery, etc.
§Quick Start (Attribute Style - Recommended)
The easiest way to write stress tests is with the #[stress_test] attribute:
ⓘ
use cntryl_stress::{stress_test, StressContext};
#[stress_test]
fn write_1mb_file(ctx: &mut StressContext) {
let data = vec![0u8; 1024 * 1024];
ctx.set_bytes(data.len() as u64);
ctx.measure(|| {
std::fs::write("/tmp/test", &data).unwrap();
});
std::fs::remove_file("/tmp/test").ok();
}
#[stress_test]
fn database_insert(ctx: &mut StressContext) {
let db = setup_database();
ctx.measure(|| {
db.insert("key", "value");
});
}
// Generate main function
cntryl_stress::stress_main!();Then run with:
cargo stress # Run all stress tests
cargo stress --workload "database*" # Run matching tests
cargo stress --workload "*insert*" # Glob patterns supported§Manual Runner Style
For more control, use the BenchRunner directly:
use cntryl_stress::{BenchRunner, StressContext};
let mut runner = BenchRunner::new("my_suite");
runner.run("expensive_operation", |ctx| {
let data = prepare_data();
ctx.measure(|| {
expensive_operation(&data);
});
cleanup(&data);
});
runner.finish();
fn prepare_data() -> Vec<u8> { vec![0; 1024] }
fn expensive_operation(_: &[u8]) {}
fn cleanup(_: &[u8]) {}§Features
- Single-shot measurements — no statistical sampling overhead
- Glob filtering — run subsets with
--workload "pattern*"
Modules§
- prelude
- Prelude module for convenient imports.
Macros§
- stress_
main - Generate the main function for running stress benchmarks.
Structs§
- Bench
Result - Result of a single benchmark measurement.
- Bench
Runner - Lightweight benchmark runner for single-shot measurements.
- Bench
Runner Config - Configuration for the benchmark runner.
- Console
Reporter - Console reporter that prints results to stdout.
- Json
Reporter - JSON reporter that writes results to a file.
- Multi
Reporter - Combines multiple reporters.
- Stress
Context - Context passed to benchmark closures for timing control.
- Stress
Runner Options - Options for running discovered benchmarks.
- Suite
Result - Results for an entire benchmark suite.
Traits§
- Reporter
- Trait for benchmark result reporters.
Functions§
- benchmark_
count - Get count of registered benchmarks.
- list_
benchmarks - Get a list of all registered benchmark names.
- run_
registered_ benchmarks - Run all registered benchmarks with default options.
- run_
with_ options - Run all registered benchmarks with custom options.
- stress_
binary_ main - Main entry point for stress test binaries generated by
stress_main!().
Attribute Macros§
- stress_
test - Mark a function as a stress benchmark.