From 4285f7f0b5bf3644b49358242d9badba8fcb2c8a Mon Sep 17 00:00:00 2001 From: Tobias Pfeiffer Date: Sun, 15 Oct 2017 22:31:45 +0200 Subject: [PATCH] Only let the user know once that we are benchmarking --- lib/benchee/benchmark/runner.ex | 3 +- lib/benchee/output/benchmark_printer.ex | 24 ++++-------- test/benchee/benchmark/runner_test.exs | 5 ++- .../benchee/output/benchmark_printer_test.exs | 37 ++++++------------- test/support/fake_benchmark_printer.ex | 8 +--- 5 files changed, 24 insertions(+), 53 deletions(-) diff --git a/lib/benchee/benchmark/runner.ex b/lib/benchee/benchmark/runner.ex index cbd37c10..50b34a0c 100644 --- a/lib/benchee/benchmark/runner.ex +++ b/lib/benchee/benchmark/runner.ex @@ -36,8 +36,7 @@ defmodule Benchee.Benchmark.Runner do printer: printer, config: config }) do - printer.input_information(input_name, config) - printer.benchmarking(job_name, config) + printer.benchmarking(job_name, input_name, config) Parallel.map(1..config.parallel, fn(_task_number) -> run_scenario(scenario, scenario_context) end) diff --git a/lib/benchee/output/benchmark_printer.ex b/lib/benchee/output/benchmark_printer.ex index 54e3fe5a..36225a74 100644 --- a/lib/benchee/output/benchmark_printer.ex +++ b/lib/benchee/output/benchmark_printer.ex @@ -70,11 +70,15 @@ defmodule Benchee.Output.BenchmarkPrinter do @doc """ Prints a notice which job is currently being benchmarked. """ - def benchmarking(_, %{print: %{benchmarking: false}}), do: nil - def benchmarking(name, _config) do - IO.puts "Benchmarking #{name}..." + def benchmarking(_, _, %{print: %{benchmarking: false}}), do: nil + def benchmarking(name, input_name, _config) do + IO.puts "Benchmarking #{name}#{input_information(input_name)}..." end + @no_input Benchmark.no_input + defp input_information(@no_input), do: "" + defp input_information(input_name), do: " with input #{input_name}" + @doc """ Prints a warning about accuracy of benchmarks when the function is super fast. """ @@ -85,18 +89,4 @@ defmodule Benchee.Output.BenchmarkPrinter do You may disable this warning by passing print: [fast_warning: false] as configuration options. """ end - - @doc """ - Prints an informative message about which input is currently being - benchmarked, when multiple inputs were specified. - """ - def input_information(_, %{print: %{benchmarking: false}}) do - nil - end - def input_information(input_name, _config) do - if input_name != Benchmark.no_input do - IO.puts "\nBenchmarking with input #{input_name}:" - end - end - end diff --git a/test/benchee/benchmark/runner_test.exs b/test/benchee/benchmark/runner_test.exs index f96d61ac..7aff66a6 100644 --- a/test/benchee/benchmark/runner_test.exs +++ b/test/benchee/benchmark/runner_test.exs @@ -153,12 +153,13 @@ defmodule Benchee.Benchmark.RunnerTest do refute_receive :called end + @no_input Benchmark.no_input() test "asks to print what is currently benchmarking" do test_suite() |> Benchmark.benchmark("Something", fn -> :timer.sleep 10 end) |> Benchmark.measure(TestPrinter) - assert_receive {:benchmarking, "Something"} + assert_receive {:benchmarking, "Something", @no_input} end @inputs %{"Arg 1" => "Argument 1", "Arg 2" => "Argument 2"} @@ -185,7 +186,7 @@ defmodule Benchee.Benchmark.RunnerTest do |> Benchmark.measure(TestPrinter) Enum.each @inputs, fn({name, _value}) -> - assert_receive {:input_information, ^name} + assert_received {:benchmarking, "one", ^name} end end diff --git a/test/benchee/output/benchmark_printer_test.exs b/test/benchee/output/benchmark_printer_test.exs index 5ea9afaf..789337cf 100644 --- a/test/benchee/output/benchmark_printer_test.exs +++ b/test/benchee/output/benchmark_printer_test.exs @@ -3,6 +3,8 @@ defmodule Benchee.Output.BenchmarkPrintertest do import ExUnit.CaptureIO import Benchee.Output.BenchmarkPrinter alias Benchee.Benchmark.Scenario + alias Benchee.Benchmark + @system_info %{elixir: "1.4", erlang: "19.2", os: :macOS, @@ -92,44 +94,27 @@ defmodule Benchee.Output.BenchmarkPrintertest do end describe ".benchmarking" do - test "prints information that it's currently benchmarking" do - output = capture_io fn -> - benchmarking("Something", %{}) - end - - assert output =~ ~r/Benchmarking.+Something/i - end - - test "doesn't print if it's deactivated" do - output = capture_io fn -> - benchmarking "A", %{print: %{benchmarking: false}} - end - - assert output == "" - end - end - describe ".input_information" do - test "notifies of the input being used" do + @no_input Benchmark.no_input() + test "prints information that it's currently benchmarking without input" do output = capture_io fn -> - input_information("Big List", %{}) + benchmarking("Something", @no_input, %{}) end - assert output =~ ~r/with input Big List/i + assert output =~ ~r/Benchmarking.+Something/i end - test "does nothing when it's the no input marker" do - marker = Benchee.Benchmark.no_input + test "prints information that it's currently benchmarking with input" do output = capture_io fn -> - input_information marker, %{} + benchmarking("Something", "great input", %{}) end - assert output == "" + assert output =~ ~r/Benchmarking.+Something with input great input/i end - test "does not print if disabled" do + test "doesn't print if it's deactivated" do output = capture_io fn -> - input_information("Big List", %{print: %{benchmarking: false}}) + benchmarking "A", "some", %{print: %{benchmarking: false}} end assert output == "" diff --git a/test/support/fake_benchmark_printer.ex b/test/support/fake_benchmark_printer.ex index 5adf141a..fb15cced 100644 --- a/test/support/fake_benchmark_printer.ex +++ b/test/support/fake_benchmark_printer.ex @@ -7,15 +7,11 @@ defmodule Benchee.Test.FakeBenchmarkPrinter do send self(), :configuration_information end - def benchmarking(name, _) do - send self(), {:benchmarking, name} + def benchmarking(name, input_information, _) do + send self(), {:benchmarking, name, input_information} end def fast_warning do send self(), :fast_warning end - - def input_information(name, _config) do - send self(), {:input_information, name} - end end