Benchee v1.0.1 Benchee.Formatter behaviour View Source

Defines a behaviour for formatters in benchee, and functions to work with these.

When implementing a benchee formatter as a behaviour please adopt this behaviour, as it helps with uniformity and also allows at least the .format function of formatters to be run in parallel.

The module itself then has functions to deal with formatters defined in this way allowing for parallel output through output/1 or just output a single formatter through output/3.

Link to this section Summary

Types

Options given to formatters, entirely defined by formatter authors

Functions

Format and output all configured formatters and formatting functions

Output a suite with a given formatter and options

Callbacks

Takes the suite and returns whatever representation the formatter wants to use to output that information. It is important that this function needs to be pure (aka have no side effects) as benchee will run format/1 functions of multiple formatters in parallel. The result will then be passed to write/1

Takes the return value of format/1 and then performs some I/O for the user to actually see the formatted data (UI, File IO, HTTP, ...)

Link to this section Types

Link to this type

options() View Source
options() :: any()

Options given to formatters, entirely defined by formatter authors.

Link to this section Functions

Format and output all configured formatters and formatting functions.

Expects a suite that already has been run through all previous functions so has the aggregated statistics etc. that the formatters rely on.

Works by invoking the format/2 and write/2 functions defined in this module. The format/2 functions are actually called in parallel (as they should be pure) - due to potential interference the write/2 functions are called serial.

Also handles pure functions that will then be called with the suite.

You can't rely on the formatters being called in pre determined order.

Link to this function

output(suite, formatter, options \\ %{}) View Source

Output a suite with a given formatter and options.

Replacement for the old MyFormatter.output/1 - calls format/2 and write/2 one after another to create the output defined by the given formatter module. For the given options please refer to the documentation of the formatters you use.

Link to this section Callbacks

Link to this callback

format(arg0, options) View Source
format(Benchee.Suite.t(), options()) :: any()

Takes the suite and returns whatever representation the formatter wants to use to output that information. It is important that this function needs to be pure (aka have no side effects) as benchee will run format/1 functions of multiple formatters in parallel. The result will then be passed to write/1.

Link to this callback

write(any, options) View Source
write(any(), options()) :: :ok | {:error, String.t()}

Takes the return value of format/1 and then performs some I/O for the user to actually see the formatted data (UI, File IO, HTTP, ...)