Benchee v1.0.1 Benchee.Scenario View Source

Core data structure representing one particular case (combination of function and input).

Represents the combination of a particular function to benchmark (also called "job" defined by job_name and function) in combination with a specific input (input_name and input). When no input is given, the combined value is representative of "no input".

A scenario then further gathers all data collected for this particular combination during Benchee.Benchmark.collect/3, which are then used later in the process by Benchee.Statistics to compute the relevant statistics which are then also added to the scenario. It is the home of the aggregated knowledge regarding this particular case/scenario.

name is the name that should be used by formatters to display scenarios as it potentially includes the tag present when loading scenarios that were saved before. See display_name/1.

Link to this section Summary

Types

t()

All the data collected for a scenario (combination of function and input)

Functions

Returns true if data of the provided type has been fully procsessed, false otherwise

Returns the correct name to display of the given scenario data

Link to this section Types

Link to this type

t() View Source
t() :: %Benchee.Scenario{
  after_each: (... -> any()) | nil,
  after_scenario: (... -> any()) | nil,
  before_each: (... -> any()) | nil,
  before_scenario: (... -> any()) | nil,
  function: (... -> any()),
  input: any() | nil,
  input_name: String.t() | nil,
  job_name: String.t(),
  memory_usage_data: Benchee.CollectionData.t(),
  name: String.t(),
  run_time_data: Benchee.CollectionData.t(),
  tag: String.t() | nil
}

All the data collected for a scenario (combination of function and input)

Among all the data required to execute the scenario (function, input, all the hooks aka after*/before*), data needed to display (name, job_name, input_name, tag) and of course run_time_data and memory_data with all the samples and computed statistics.

Link to this section Functions

Link to this function

data_processed?(scenario, atom) View Source
data_processed?(t(), :run_time | :memory) :: boolean()

Returns true if data of the provided type has been fully procsessed, false otherwise.

Current available types are run_time and memory. Reasons they might not have been processed yet are:

  • Suite wasn't configured to collect them at all
  • Benchee.statistics/1 hasn't been called yet so that data was collected but statistics aren't present yet

Examples

iex> alias Benchee.Scenario
iex> alias Benchee.Statistics
iex> scenario = %Scenario{run_time_data: %Benchee.CollectionData{statistics: %Statistics{sample_size: 100}}}
iex> Scenario.data_processed?(scenario, :run_time)
true
iex> scenario = %Scenario{memory_usage_data: %Benchee.CollectionData{statistics: %Statistics{sample_size: 1}}}
iex> Scenario.data_processed?(scenario, :memory)
true
iex> scenario = %Scenario{memory_usage_data: %Benchee.CollectionData{statistics: %Statistics{sample_size: 0}}}
iex> Scenario.data_processed?(scenario, :memory)
false
Link to this function

display_name(map) View Source
display_name(t()) :: String.t()

Returns the correct name to display of the given scenario data.

In the normal case this is job_name, however when scenarios are loaded they are tagged and these tags should be shown for disambiguation.

Examples

iex> alias Benchee.Scenario
iex> Scenario.display_name(%Scenario{job_name: "flat_map"})
"flat_map"
iex> Scenario.display_name(%Scenario{job_name: "flat_map", tag: "master"})
"flat_map (master)"
iex> Scenario.display_name(%{job_name: "flat_map"})
"flat_map"