Struct Benchmarks

Source
pub struct Benchmarks<C, W, E>
where C: Clone + Display, W: Clone + Display, Error: From<E>,
{ /* private fields */ }
Expand description

Run and analyze a benchmarks suite

  • C - configuration
  • W - workload unit
  • E - error type

Implementations§

Source§

impl<C, W, E> Benchmarks<C, W, E>
where C: Clone + Display, W: Clone + Display, Error: From<E>,

Source

pub fn new(name: &str) -> Benchmarks<C, W, E>

Create a new Benchmarks

  • name - the name of the benchmark session
Source

pub fn run(&mut self) -> Result<(), Error>

Run all benchmarks

Source

pub fn add( &mut self, name: &str, f: fn(stop_watch: &mut StopWatch, config: C, workload_point: W) -> Result<(), E>, config: C, work: Vec<W>, repeat: usize, ramp_up: usize, ) -> Result<(), Error>

Create and add a Benchmark

  • name - the name of the benchmark series. The result will be accessible by the name as a key from the summary.
  • f - the function that runs the benchmark.
  • config - the configuration value for this benchmark series
  • work - workload points vector for this benchmark series. Elements of this vector are passed to f in each iteration
  • repeat - number of times the benchmark will be repeated
  • ramp_up - number of times the benchmark will be performed before the measurement is taken
Source

pub fn summary(&self) -> Summary

Produce Summary for all series

Source

pub fn summary_as_json(&self) -> String

Produce Summary for all series as JSON string.

Source

pub fn summary_as_csv( &self, with_headers: bool, with_config: bool, ) -> HashMap<String, Vec<String>>

Produce summary for each series as vector of CSV lines. The key for series data is the series name used in Self::add method, values are placed as the headers returned by [Self::csv_headers]

Source

pub fn save_to_csv( &self, dir: PathBuf, with_headers: bool, with_config: bool, ) -> Result<(), Error>

Save each benchmark summary to its own CSV file

The name of each CSV file is the name of the benchmark.

  • dir - directory to store results. If doesn’t exist - create it.
  • with_headers - add column headers on the first line
  • with_config - add the configuration string in the headers row
use std::path::PathBuf;
use benchmark_rs::benchmarks::Benchmarks;
let benchmarks = Benchmarks::<usize, usize, anyhow::Error>::new("example");
benchmarks.save_to_csv(PathBuf::from("./target/benchmarks"), true, true).expect("failed to save to csv");
Source

pub fn save_to_json(&self, dir: PathBuf) -> Result<(), Error>

Save the summary to a json file.

The name of the JSON file is the name of the suite of benchmarks. If dir doesn’t exist - create it.

use std::path::PathBuf;
use anyhow::anyhow;
use benchmark_rs::benchmarks::Benchmarks;
let benchmarks = Benchmarks::<usize, usize, anyhow::Error>::new("example");
benchmarks.save_to_json(PathBuf::from("./target/benchmarks")).expect("failed to save to json");
Source

pub fn configs(&self) -> HashMap<String, String>

Produce description of configurations for each series. The key for series config is the series name used in Self::add method.

Source

pub fn name(&self) -> &String

The benchmarks suite name

Source

pub fn analyze( &self, prev_result_string_opt: Option<String>, threshold: f64, ) -> Result<AnalysisResult, Error>

Compare the current result against a previous result.

  • prev_result_string_opt - a JSON string of the Summary of previous run
  • threshold - threshold used to determine equality.

Auto Trait Implementations§

§

impl<C, W, E> Freeze for Benchmarks<C, W, E>
where Error: Sized,

§

impl<C, W, E> RefUnwindSafe for Benchmarks<C, W, E>

§

impl<C, W, E> Send for Benchmarks<C, W, E>
where Error: Sized, C: Send, W: Send,

§

impl<C, W, E> Sync for Benchmarks<C, W, E>
where Error: Sized, C: Sync, W: Sync,

§

impl<C, W, E> Unpin for Benchmarks<C, W, E>
where Error: Sized, C: Unpin, W: Unpin,

§

impl<C, W, E> UnwindSafe for Benchmarks<C, W, E>

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, 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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V