Trait Payload

Source
pub trait Payload:
    Sized
    + Send
    + 'static {
    // Required methods
    fn new_pair() -> (Self, Self);
    fn prepare(&mut self);
    fn process(&mut self);
}
Expand description

One benchmark payload, to be processed by each worker involved in each benchmark.

Payloads are created in pairs because the workers are created in pairs. Depending on the benchmark scenario, the pair of payloads may be connected (e.g. reader and writer) or independent (equivalent, two workers doing the same thing).

The lifecycle of a payload is:

  1. A payload pair is created on the main thread.
  2. Each payload in the pair is transferred to a specific thread hosting a specific worker.
  3. The prepare() method is called to generate any input data.
  4. The payload pair is exchanged between the two paired workers.
  5. The process() method is called to process the data received from the other pair member.
  6. The payload pair is dropped.

Note that some work distribution modes (named *Self) may skip the payload exchange step.

Required Methods§

Source

fn new_pair() -> (Self, Self)

Creates the payload pair that will be used to initialize one worker pair in one benchmark iteration. This will be called on the main thread.

Source

fn prepare(&mut self)

Performs any initialization required. This will be called before the benchmark time span measurement starts. It will be called on a worker thread but the payload may be moved to a different worker thread before the benchmark starts (as workers by default prepare work for each other, to showcase what happens when the work is transferred between threads).

Source

fn process(&mut self)

Processes the payload but does not consume it. The iteration is complete when this returns for all payloads. The payloads are dropped later, to ensure that the benchmark time is not affected by the time it takes to drop the payload and release the memory.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§