Skip to content

Commit

Permalink
Modifying extended statistics config key name, cleaning up output log…
Browse files Browse the repository at this point in the history
…ic paths
  • Loading branch information
lwalter committed Oct 23, 2017
1 parent 850ee97 commit ec3acd5
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 48 deletions.
10 changes: 5 additions & 5 deletions lib/benchee/configuration.ex
Expand Up @@ -28,7 +28,7 @@ defmodule Benchee.Configuration do
formatter_options: %{
console: %{
comparison: true,
extended_options: false
extended_statistics: false
}
},
unit_scaling: :best,
Expand Down Expand Up @@ -141,7 +141,7 @@ defmodule Benchee.Configuration do
configuration: true
},
formatter_options: %{
console: %{comparison: true, extended_options: false}
console: %{comparison: true, extended_statistics: false}
},
unit_scaling: :best,
assigns: %{},
Expand Down Expand Up @@ -169,7 +169,7 @@ defmodule Benchee.Configuration do
configuration: true
},
formatter_options: %{
console: %{comparison: true, extended_options: false}
console: %{comparison: true, extended_statistics: false}
},
unit_scaling: :best,
assigns: %{},
Expand Down Expand Up @@ -197,7 +197,7 @@ defmodule Benchee.Configuration do
configuration: true
},
formatter_options: %{
console: %{comparison: true, extended_options: false}
console: %{comparison: true, extended_statistics: false}
},
unit_scaling: :best,
assigns: %{},
Expand Down Expand Up @@ -234,7 +234,7 @@ defmodule Benchee.Configuration do
configuration: true
},
formatter_options: %{
console: %{comparison: false, extended_options: false},
console: %{comparison: false, extended_statistics: false},
some: "option"
},
unit_scaling: :smallest,
Expand Down
55 changes: 34 additions & 21 deletions lib/benchee/formatters/console.ex
Expand Up @@ -63,7 +63,7 @@ defmodule Benchee.Formatters.Console do
...> scenarios: scenarios,
...> configuration: %Benchee.Configuration{
...> formatter_options: %{
...> console: %{comparison: false, extended_options: false}
...> console: %{comparison: false, extended_statistics: false}
...> },
...> unit_scaling: :best
...> }
Expand Down Expand Up @@ -135,15 +135,15 @@ defmodule Benchee.Formatters.Console do
...> }
...> }
...> ]
iex> configuration = %{comparison: false, unit_scaling: :best, extended_options: true}
iex> configuration = %{comparison: false, unit_scaling: :best, extended_statistics: true}
iex> Benchee.Formatters.Console.format_scenarios(scenarios, configuration)
["\nName ips average deviation median 99th %\n",
"My Job 5 K 200 μs ±10.00% 190 μs 300.10 μs\n",
"Job 2 2.50 K 400 μs ±20.00% 390 μs 500.10 μs\n",
"\nExtended options: \n",
"\nExtended statistics: \n",
"\nName minimum maximum sample size mode\n",
"My Job 100.10 μs 200.20 μs 10101 333.20 μs\n",
"Job 2 200.20 μs 400.40 μs 20202 612.30 μs, 554.10 μs\n"]
"My Job 100.10 μs 200.20 μs 10.10 K 333.20 μs\n",
"Job 2 200.20 μs 400.40 μs 20.20 K 612.30 μs, 554.10 μs\n"]
```
Expand All @@ -155,34 +155,44 @@ defmodule Benchee.Formatters.Console do
units = Conversion.units(sorted_scenarios, scaling_strategy)
label_width = label_width(sorted_scenarios)

output = [column_descriptors(label_width) |
[column_descriptors(label_width) |
scenario_reports(sorted_scenarios, units, label_width)
++ comparison_report(sorted_scenarios, units, label_width, config)]

if config.extended_options do
output ++ [descriptor("Extended options") |
[extended_column_descriptors(label_width)]
++ extended_options_reports(sorted_scenarios, units, label_width)]
else
output
end
++ comparison_report(sorted_scenarios, units, label_width, config)
++ extended_statistics_report(
sorted_scenarios, units, label_width, config)]
end

@spec extended_options_reports([Scenario.t], map, integer) :: [any, ...]
defp extended_options_reports(scenarios, units, label_width) do
@spec extended_statistics_report(
[Scenario.t], unit_per_statistic, integer, map) :: [String.t]
defp extended_statistics_report(_, _, _, %{extended_statistics: false}) do
[]
end
defp extended_statistics_report(scenarios, units, label_width, _config) do
[
descriptor("Extended statistics"),
extended_column_descriptors(label_width) |
extended_statistics(scenarios, units, label_width)
]
end

@spec extended_statistics([Scenario.t], unit_per_statistic, integer)
:: [String.t]
defp extended_statistics(scenarios, units, label_width) do
Enum.map(scenarios, fn(scenario) ->
format_scenario_extended(scenario, units, label_width) end)
format_scenario_extended(scenario, units, label_width)
end)
end

@spec format_scenario_extended(Scenario.t, map, integer) :: String.t
@spec format_scenario_extended(Scenario.t, unit_per_statistic, integer)
:: String.t
defp format_scenario_extended(%Scenario{
job_name: name,
run_time_statistics: %Statistics{
minimum: minimum,
maximum: maximum,
sample_size: sample_size,
mode: mode
},
}
},
%{run_time: run_time_unit},
label_width) do
Expand All @@ -191,12 +201,15 @@ defmodule Benchee.Formatters.Console do
-label_width, name,
@minimum_width, run_time_out(minimum, run_time_unit),
@maximum_width, run_time_out(maximum, run_time_unit),
@sample_size_width, to_string(sample_size),
@sample_size_width, Count.format(sample_size),
@mode_width, mode_out(mode, run_time_unit)])
|> to_string
end

@spec mode_out([number], Benchee.Conversion.Unit.t) :: String.t
defp mode_out(modes, _run_time_unit) when is_nil(modes) do
"None"
end
defp mode_out(modes, run_time_unit) when is_list(modes) do
Enum.map_join(modes, ", ", fn(mode) -> run_time_out(mode, run_time_unit) end)
end
Expand Down
4 changes: 2 additions & 2 deletions test/benchee/configuration_test.exs
Expand Up @@ -38,7 +38,7 @@ defmodule Benchee.ConfigurationTest do
time: 10,
formatter_options: %{
custom: %{option: true},
console: %{extended_options: true}
console: %{extended_statistics: true}
}
}

Expand All @@ -48,7 +48,7 @@ defmodule Benchee.ConfigurationTest do
time: 10,
formatter_options: %{
custom: %{option: true},
console: %{comparison: true, extended_options: true}
console: %{comparison: true, extended_statistics: true}
}
}

Expand Down
59 changes: 39 additions & 20 deletions test/benchee/formatters/console_test.exs
Expand Up @@ -10,15 +10,20 @@ defmodule Benchee.Formatters.ConsoleTest do
@console_config %{
comparison: true,
unit_scaling: :best,
extended_options: false
extended_statistics: false
}
@console_config_extended_params %{
comparison: true,
unit_scaling: :best,
extended_options: true
extended_statistics: true
}
@config %Benchee.Configuration{
formatter_options: %{console: %{comparison: true, extended_options: false}}
formatter_options: %{
console: %{
comparison: true,
extended_statistics: false
}
}
}
describe ".output" do
test "formats and prints the results right to the console" do
Expand Down Expand Up @@ -65,7 +70,7 @@ defmodule Benchee.Formatters.ConsoleTest do
end

describe ".format_scenarios" do
test "displays extended options" do
test "displays extended statistics" do
scenarios = [
%Scenario{
job_name: "First job",
Expand All @@ -86,19 +91,19 @@ defmodule Benchee.Formatters.ConsoleTest do
[_header1, _result1, descriptor1, descriptor2, result2] =
Console.format_scenarios(scenarios, @console_config_extended_params)

assert descriptor1 =~ ~r/Extended options: /
assert descriptor1 =~ ~r/Extended statistics: /
assert descriptor2 =~ ~r/minimum/
assert descriptor2 =~ ~r/maximum/
assert descriptor2 =~ ~r/sample size/
assert descriptor2 =~ ~r/mode/
assert result2 =~ ~r/First job/
assert result2 =~ ~r/111.10/
assert result2 =~ ~r/333.30/
assert result2 =~ ~r/50000/
assert result2 =~ ~r/50 K/
assert result2 =~ ~r/201.20/
end

test "displays extended options with multiple mode ouput" do
test "displays extended statistics with multiple mode ouput" do
scenarios = [
%Scenario{
job_name: "First job",
Expand All @@ -116,20 +121,34 @@ defmodule Benchee.Formatters.ConsoleTest do
}
]

[_header1, _result1, descriptor1, descriptor2, result2] =
[_header1, _result1, _header2, _header3, result2] =
Console.format_scenarios(scenarios, @console_config_extended_params)

assert descriptor1 =~ ~r/Extended options: /
assert descriptor2 =~ ~r/minimum/
assert descriptor2 =~ ~r/maximum/
assert descriptor2 =~ ~r/sample size/
assert descriptor2 =~ ~r/mode/
assert result2 =~ ~r/First job/
assert result2 =~ ~r/111.10/
assert result2 =~ ~r/333.30/
assert result2 =~ ~r/50000/
assert result2 =~ ~r/201.20/
assert result2 =~ ~r/205.55/
assert result2 =~ ~r/201.20 μs/
assert result2 =~ ~r/205.55 μs/
end

test "displays N/A when no mode exists" do
scenarios = [
%Scenario{
job_name: "First job",
run_time_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,
sample_size: 50_000
}
}
]

[_header1, _result1, _header2, _header3, result2] =
Console.format_scenarios(scenarios, @console_config_extended_params)

assert result2 =~ ~r/None/
end

test "sorts the the given stats fastest to slowest" do
Expand Down Expand Up @@ -291,7 +310,7 @@ defmodule Benchee.Formatters.ConsoleTest do
%{
comparison: false,
unit_scaling: :best,
extended_options: false
extended_statistics: false
})

refute Regex.match? ~r/Comparison/i, output
Expand Down

0 comments on commit ec3acd5

Please sign in to comment.