View Source BencheeAsync.Reporter (BencheeAsync v0.1.1)

The GenServer responsible for tracking units of work done.

To allow for more flexibility, this GenServer must be started manually before beginning the benchmarking as part of the benchmark suite setup.

# in an .exs script
Elixir.BencheeAsync.Reporter.start_link()

# in an ExUnit test
start_supervised!(Elixir.BencheeAsync.Reporter)

Reporting

To report a unit of work done, execute Elixir.BencheeAsync.Reporter.report/0 anywhere within your application code.

To avoid introducing dev-specific logic into your application code, it is advised to use a mocking library to mock your internal functions. :meck or Mimic will both work, the choice between either or otherwise would be a matter of taste.

For example, with Mimic:

# test/test_helper.exs
Mimic.copy(MyApp)
ExUnit.start()
# test/my_app_test.exs
defmodule MyAppTest do
  use ExUnit.Case, async: false
  use Mimic

  @tag :benchmark
  test "benchmarking async work!" do
    MyApp
    |> stub(:do_work, fn _arg ->
      Elixir.BencheeAsync.Reporter.report()
      :ok
    end)

    # benchmarking code goes here...
    BencheeAsync.run(%{....})
  end
end

Summary

Functions

Returns a specification to start this module under a supervisor.

Resets the state within the Reporter. This is not called automatically after the benchmark is run, as it is expected that the Reporter process terminates after each benchmark run.

Retrieves the samples recorded for a given scenario and input combination.

Records a unit of work done. Should be called each time a unit of work is performed.

Functions

Returns a specification to start this module under a supervisor.

See Supervisor.

@spec clear() :: :ok

Resets the state within the Reporter. This is not called automatically after the benchmark is run, as it is expected that the Reporter process terminates after each benchmark run.

If this is not the case for you, you can run this manually between benchmark runs as so:

BencheeAsync.run(%{...})
BencheeAsync.Reporter.clear()
BencheeAsync.run(%{...})

If the scenario names are different between each benchmark run, then clearing the state would not be necessary.

Link to this function

get_samples(scenario_name, input \\ :__no_input)

View Source
@spec get_samples(String.t(), term() | :__no_input) :: [integer()]

Retrieves the samples recorded for a given scenario and input combination.

@spec record() :: :ok

Records a unit of work done. Should be called each time a unit of work is performed.

It is advised to mock the function that you wish to track and call this function within the mock.