Crate cntryl_stress

Crate cntryl_stress 

Source
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.

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§

BenchResult
Result of a single benchmark measurement.
BenchRunner
Lightweight benchmark runner for single-shot measurements.
BenchRunnerConfig
Configuration for the benchmark runner.
ConsoleReporter
Console reporter that prints results to stdout.
JsonReporter
JSON reporter that writes results to a file.
MultiReporter
Combines multiple reporters.
StressContext
Context passed to benchmark closures for timing control.
StressRunnerOptions
Options for running discovered benchmarks.
SuiteResult
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.