Skip to content

Commit

Permalink
Only show extended memory statistics when requested
Browse files Browse the repository at this point in the history
  • Loading branch information
PragTob committed Apr 9, 2019
1 parent 408ca94 commit 72cd7bc
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/benchee/formatters/console/memory.ex
Expand Up @@ -254,17 +254,19 @@ defmodule Benchee.Formatters.Console.Memory do
Memory.format({Memory.scale(memory, unit), unit})
end

defp extended_statistics_report(_, _, _, %{extended_statistics: false}, _), do: []
defp extended_statistics_report(scenarios, units, label_width, config, hide_statistics)
defp extended_statistics_report(_, _, _, _, true), do: []

defp extended_statistics_report(scenarios, units, label_width, _config, _hide_statistics) do
defp extended_statistics_report(scenarios, units, label_width, %{extended_statistics: true}, _) do
[
Helpers.descriptor("Extended statistics"),
extended_column_descriptors(label_width)
| extended_statistics(scenarios, units, label_width)
]
end

defp extended_statistics_report(_, _, _, _, _), do: []

defp extended_column_descriptors(label_width) do
"\n~*s~*s~*s~*s~*s\n"
|> :io_lib.format([
Expand Down
38 changes: 38 additions & 0 deletions test/benchee/formatters/console/memory_test.exs
Expand Up @@ -330,6 +330,44 @@ defmodule Benchee.Formatters.Console.MemoryTest do
assert result2 =~ "201.20"
end

test "doesn't display extended statistics if extended_statistics isn't specified" do
scenarios = [
%Scenario{
name: "First job",
memory_usage_data: %CollectionData{
statistics: %Statistics{
average: 200.0,
ips: 5_000.0,
std_dev_ratio: 0.1,
median: 195.5,
percentiles: %{99 => 300.1},
minimum: 111.1,
maximum: 333.3,
mode: 201.2,
sample_size: 50_000
}
},
run_time_data: %CollectionData{statistics: %Statistics{average: 100.0, ips: 1_000.0}}
}
]

params = %{
unit_scaling: :best
}

output = scenarios |> Memory.format_scenarios(params) |> Enum.join("")

refute output =~ "Extended statistics: "
refute output =~ "minimum"
refute output =~ "maximum"
refute output =~ "sample size"
refute output =~ "mode"
refute output =~ "111.10"
refute output =~ "333.30"
refute output =~ "50 K"
refute output =~ "201.20"
end

test "does nothing when there's no statistics to format" do
scenarios = [
%Scenario{memory_usage_data: %CollectionData{statistics: %Statistics{sample_size: 0}}}
Expand Down

0 comments on commit 72cd7bc

Please sign in to comment.