pub struct Benchmark<W = ()> { /* private fields */ }Expand description
Benchmark builder for the request/response pattern.
Benchmark::new()
.rate(1000.0) // 1000 total req/s (shared pool)
.workers(4)
.duration_secs(10)
.work(HttpWork { client, url })
.run()
.await
.print_summary();Implementations§
Source§impl Benchmark<()>
impl Benchmark<()>
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new benchmark with default settings.
Defaults: unlimited rate, 1 worker, 10s duration, 100ms warmup.
Sourcepub fn from_config(config: BenchmarkConfig) -> Self
pub fn from_config(config: BenchmarkConfig) -> Self
Create a Benchmark from a BenchmarkConfig.
All fields of the config are applied to the builder; the result is
ready for .work(…).run().
Source§impl<W> Benchmark<W>
impl<W> Benchmark<W>
Sourcepub fn rate(self, rate: f64) -> Self
pub fn rate(self, rate: f64) -> Self
Set total requests per second, shared across all workers.
Use <= 0 for unlimited rate.
Sourcepub fn rate_per_worker(self, rate: f64) -> Self
pub fn rate_per_worker(self, rate: f64) -> Self
Set requests per second per worker (each worker gets its own limiter).
Use <= 0 for unlimited rate.
Sourcepub fn ramp_up(self, duration: Duration) -> Self
pub fn ramp_up(self, duration: Duration) -> Self
Set the ramp-up duration before the measured benchmark starts.
During ramp-up, workers run at a linearly increasing rate from
ramp_start_rate up to the configured target
rate. Stats are collected into the same pool as the main phase.
Sourcepub fn ramp_start_rate(self, rate: f64) -> Self
pub fn ramp_start_rate(self, rate: f64) -> Self
Set the initial rate at the start of the ramp-up period (default: 0.0).
Has no effect if ramp_up is not set.
Sourcepub fn burst_factor(self, factor: f64) -> Self
pub fn burst_factor(self, factor: f64) -> Self
Set the burst factor for the rate controller (default: 0.1).
Controls how many seconds’ worth of tokens may accumulate while the
system is idle. For example 0.5 allows up to 500 ms of burst before
the bucket is full.
Sourcepub fn show_ramp_progress(self, show: bool) -> Self
pub fn show_ramp_progress(self, show: bool) -> Self
Show progress during the ramp-up period (default: true).
When true, snapshot lines are displayed with a [RAMP] prefix
during the ramp phase. Set to false to suppress output until
ramp completes.
Sourcepub fn duration_secs(self, secs: u64) -> Self
pub fn duration_secs(self, secs: u64) -> Self
Set benchmark duration in seconds.
Sourcepub fn snapshot_interval(self, interval: Duration) -> Self
pub fn snapshot_interval(self, interval: Duration) -> Self
Set snapshot interval.
Sourcepub fn snapshot_interval_secs(self, secs: u64) -> Self
pub fn snapshot_interval_secs(self, secs: u64) -> Self
Set snapshot interval in seconds.
Sourcepub fn progress(self, show: bool) -> Self
pub fn progress(self, show: bool) -> Self
Enable/disable live progress display (default: true).
When disabled, raw CSV rows are written to stdout instead.
Sourcepub fn on_progress<F>(self, f: F) -> Self
pub fn on_progress<F>(self, f: F) -> Self
Set a custom progress formatter.
The closure receives a StatsSnapshot and returns the message to
print (without timestamp — the [N.NNNs] prefix is always prepended).
Return None to suppress the line for that interval.
Overrides the default "N req | N req/s | p50=…ms | N% ok" format.
Has no effect when progress is set to false.
Sourcepub fn work<W2: BenchmarkWork>(self, work: W2) -> Benchmark<W2>
pub fn work<W2: BenchmarkWork>(self, work: W2) -> Benchmark<W2>
Set the work implementation.
The framework clones work once per worker. Put shared resources
(connection pools, HTTP clients) in the struct; per-worker resources
go in Work::State via BenchmarkWork::init.
Source§impl<W: BenchmarkWork> Benchmark<W>
impl<W: BenchmarkWork> Benchmark<W>
Sourcepub async fn run(self) -> BenchmarkResults
pub async fn run(self) -> BenchmarkResults
Run the benchmark and return results.