Skip to main content

Benchmark

Struct Benchmark 

Source
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<()>

Source

pub fn new() -> Self

Create a new benchmark with default settings.

Defaults: unlimited rate, 1 worker, 10s duration, 100ms warmup.

Source

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>

Source

pub fn rate(self, rate: f64) -> Self

Set total requests per second, shared across all workers.

Use <= 0 for unlimited rate.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn workers(self, workers: usize) -> Self

Set number of worker tasks.

Source

pub fn duration(self, duration: Duration) -> Self

Set benchmark duration.

Source

pub fn duration_secs(self, secs: u64) -> Self

Set benchmark duration in seconds.

Source

pub fn warmup(self, warmup: Duration) -> Self

Set warmup duration before measurements start.

Source

pub fn no_warmup(self) -> Self

Disable warmup.

Source

pub fn snapshot_interval(self, interval: Duration) -> Self

Set snapshot interval.

Source

pub fn snapshot_interval_secs(self, secs: u64) -> Self

Set snapshot interval in seconds.

Source

pub fn csv<P: Into<PathBuf>>(self, path: P) -> Self

Set CSV output file path.

Source

pub fn progress(self, show: bool) -> Self

Enable/disable live progress display (default: true).

When disabled, raw CSV rows are written to stdout instead.

Source

pub fn on_progress<F>(self, f: F) -> Self
where F: Fn(&StatsSnapshot) -> Option<String> + Send + Sync + 'static,

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.

Source

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>

Source

pub async fn run(self) -> BenchmarkResults

Run the benchmark and return results.

Trait Implementations§

Source§

impl Default for Benchmark<()>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl From<BenchmarkConfig> for Benchmark<()>

Source§

fn from(config: BenchmarkConfig) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<W> Freeze for Benchmark<W>
where W: Freeze,

§

impl<W = ()> !RefUnwindSafe for Benchmark<W>

§

impl<W> Send for Benchmark<W>
where W: Send,

§

impl<W> Sync for Benchmark<W>
where W: Sync,

§

impl<W> Unpin for Benchmark<W>
where W: Unpin,

§

impl<W> UnsafeUnpin for Benchmark<W>
where W: UnsafeUnpin,

§

impl<W = ()> !UnwindSafe for Benchmark<W>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more