Skip to content

Commit

Permalink
Add mode display
Browse files Browse the repository at this point in the history
  • Loading branch information
PragTob committed Mar 9, 2019
1 parent a7e969d commit 1dde46c
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 12 deletions.
14 changes: 14 additions & 0 deletions lib/benchee/formatters/render.ex
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,20 @@ defmodule Benchee.Formatters.HTML.Render do
})
end

defp format_mode(nil, _unit) do
"none"
end

defp format_mode(modes = [_ | _], unit) do
modes
|> Enum.map(fn mode -> format_property(mode, unit) end)
|> Enum.join(", ")
end

defp format_mode(value, unit) do
format_property(value, unit)
end

defp format_property(value, unit) do
Format.format({Scale.scale(value, unit), unit})
end
Expand Down
3 changes: 3 additions & 0 deletions priv/templates/partials/data_table.html.eex
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<th>Average</th>
<th>Deviation</th>
<th>Median</th>
<th>Mode</th>
<th>Minimum</th>
<th>Maximum</th>
<th>Sample size</th>
Expand All @@ -28,12 +29,14 @@
<td><%= format_property statistics.average, units.run_time %></td>
<td><%= format_percent statistics.std_dev_ratio %></td>
<td><%= format_property statistics.median, units.run_time %></td>
<td><%= format_mode statistics.mode, units.run_time %></td>
<td><%= format_property statistics.minimum, units.run_time %></td>
<td><%= format_property statistics.maximum, units.run_time %></td>
<% else %>
<td><%= format_property statistics.average, units.memory %></td>
<td><%= format_percent statistics.std_dev_ratio %></td>
<td><%= format_property statistics.median, units.memory %></td>
<td><%= format_mode statistics.mode, units.memory %></td>
<td><%= format_property statistics.minimum, units.memory %></td>
<td><%= format_property statistics.maximum, units.memory %></td>
<% end %>
Expand Down
71 changes: 59 additions & 12 deletions test/benchee/formatters/html_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,34 @@ defmodule Benchee.Formatters.HTMLTest do
cpu_speed: "2.80GHz",
num_cores: 2
}
@run_time_statistics %Benchee.Statistics{
average: 200.0,
ips: 5000.0,
std_dev: 20,
std_dev_ratio: 0.1,
std_dev_ips: 500,
median: 190.0,
mode: 205,
sample_size: 3,
minimum: 190,
maximum: 210
}
@scenario %Benchee.Benchmark.Scenario{
job_name: "My Job",
name: "My Job",
run_times: [190, 200, 210],
memory_usages: [190, 200, 210],
input_name: "Some Input",
input: "Some Input",
run_time_statistics: %Benchee.Statistics{
average: 200.0,
ips: 5000.0,
std_dev: 20,
std_dev_ratio: 0.1,
std_dev_ips: 500,
median: 190.0,
sample_size: 3,
minimum: 190,
maximum: 210
},
run_time_statistics: @run_time_statistics,
memory_usage_statistics: %Benchee.Statistics{
average: 200.0,
ips: nil,
std_dev: 20,
std_dev_ratio: 0.1,
std_dev_ips: nil,
median: 190.0,
mode: 205,
sample_size: 3,
minimum: 190,
maximum: 210
Expand Down Expand Up @@ -76,10 +79,12 @@ defmodule Benchee.Formatters.HTMLTest do
">190 ns<",
">210 ns<",
">200 ns<",
">205 ns<",
"5 K",
">190 B<",
">210 B<",
">200 B<"
">200 B<",
">205 B<"
]
)
end)
Expand Down Expand Up @@ -188,6 +193,48 @@ defmodule Benchee.Formatters.HTMLTest do
end
end

test "deals with no mode being present" do
suite = %Benchee.Suite{
scenarios: [
%Benchee.Benchmark.Scenario{
@scenario
| run_time_statistics: %Benchee.Statistics{
@run_time_statistics
| mode: nil
}
}
],
system: @system_info
}

[comparison_html, scenario_html] = comparison_and_job_htmls(suite)

Enum.each([comparison_html, scenario_html], fn html ->
assert html =~ ">none<"
end)
end

test "deals with multiple modes being present" do
suite = %Benchee.Suite{
scenarios: [
%Benchee.Benchmark.Scenario{
@scenario
| run_time_statistics: %Benchee.Statistics{
@run_time_statistics
| mode: [190, 200, 210]
}
}
],
system: @system_info
}

[comparison_html, scenario_html] = comparison_and_job_htmls(suite)

Enum.each([comparison_html, scenario_html], fn html ->
assert html =~ ">190 ns, 200 ns, 210 ns<"
end)
end

describe "write/2" do
test "does not copy assets when inlining is on" do
options = %{file: @filename, auto_open: false, inline_assets: true}
Expand Down

0 comments on commit 1dde46c

Please sign in to comment.