benchee_json v0.4.0 Benchee.Formatters.JSON

Functionality for converting Benchee benchmarking results to JSON so that they can be written to file or just generated for your usage.

The most basic use case is to configure it as one of the formatters to be used by Benchee.run/2.

list = Enum.to_list(1..10_000)
map_fun = fn(i) -> [i, i * i] end

Benchee.run(%{
    "flat_map"    => fn -> Enum.flat_map(list, map_fun) end,
    "map.flatten" => fn -> list |> Enum.map(map_fun) |> List.flatten end
  },
  formatters: [
    &Benchee.Formatters.JSON.output/1,
    &Benchee.Formatters.Console.output/1
  ],
  formatter_options: [json: [file: "my.json"]]
)

Summary

Functions

Simple wrapper for encoding a map/benchee structure to JSON

Formats the output of benchee to a map from input names to their associated JSON with run_times and statistics

Combines format/1 and write/1 into a single convenience function that is also chainable (as it takes a suite and returns a suite)

Uses the return value of Benchee.Formatters.JSON.format/1 to write it to the JSON file defined in the initial configuration under formatter_options: %{json: %{file: "my.json"}}

Functions

encode!(benchee_structure)

Simple wrapper for encoding a map/benchee structure to JSON.

Decouples it from the actual JSON library (currently Poison) used by benchee_json so that other plugins can rely on it just working with a general Benchee suite structure.

format(arg1)
format(Benchee.Suite.t) :: {%{optional(Benchee.Suite.key) => String.t}, String.t}

Formats the output of benchee to a map from input names to their associated JSON with run_times and statistics.

Examples

iex> suite = %Benchee.Suite{
...>      scenarios: [
...>        %Benchee.Benchmark.Scenario{
...>          job_name: "My Job",
...>          run_times: [200, 400, 400, 400, 500, 500, 700, 900],
...>          input_name: "Some Input",
...>          input: "Some Input",
...>          run_time_statistics: %Benchee.Statistics{
...>            average:       500.0,
...>            ips:           2000.0,
...>            std_dev:       200.0,
...>            std_dev_ratio: 0.4,
...>            std_dev_ips:   800.0,
...>            median:        450.0,
...>            minimum:       200,
...>            maximum:       900,
...>            mode:          400,
...>            sample_size:   8,
...>            percentiles:   %{99 => 900}
...>          }
...>        },
...>      ],
...>      configuration: %Benchee.Configuration{
...>        formatter_options: %{json: %{file: "my_file.json"}}
...>      }
...>    }
iex> Benchee.Formatters.JSON.format(suite)
{%{"Some Input" => "{\"statistics\":{\"My Job\":{\"std_dev_ratio\":0.4,\"std_dev_ips\":800.0,\"std_dev\":200.0,\"sample_size\":8,\"percentiles\":{\"99\":900},\"mode\":400,\"minimum\":200,\"median\":450.0,\"maximum\":900,\"ips\":2.0e3,\"average\":500.0}},\"sort_order\":[\"My Job\"],\"run_times\":{\"My Job\":[200,400,400,400,500,500,700,900]}}"}, "my_file.json"}
format_scenarios_for_input(scenarios)
output(suite)

Combines format/1 and write/1 into a single convenience function that is also chainable (as it takes a suite and returns a suite).

write(arg)
write({%{optional(Benchee.Suite.key) => String.t}, String.t}) :: :ok

Uses the return value of Benchee.Formatters.JSON.format/1 to write it to the JSON file defined in the initial configuration under formatter_options: %{json: %{file: "my.json"}}