From f03b40a813217957c4ec594cb4f5fc9bf1c85787 Mon Sep 17 00:00:00 2001 From: Devon Estes Date: Thu, 28 Jun 2018 14:24:36 +0200 Subject: [PATCH] Add warning when protocols are not consolidated This adds a warning when folks try to run benchmarks in environments without protocol consolidation enabled. I have no idea how to test this since you can't turn protocol consolidation off at runtime, though. --- lib/benchee/system.ex | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/lib/benchee/system.ex b/lib/benchee/system.ex index 9e2d946d..d1dadece 100644 --- a/lib/benchee/system.ex +++ b/lib/benchee/system.ex @@ -20,6 +20,8 @@ defmodule Benchee.System do cpu_speed: cpu_speed() } + warn_about_performance_degrading_settings() + %Suite{suite | system: system_info} end @@ -164,4 +166,22 @@ defmodule Benchee.System do output end end + + defp warn_about_performance_degrading_settings do + unless all_protocols_consolidated?() do + IO.puts(""" + Not all of your protocols have been consolidated. In order to achieve the + best possible accuracy for benchmarks, please ensure protocol + consolidation is enabled in your benchmarking environment. + """) + end + end + + defp all_protocols_consolidated? do + path = :code.lib_dir(:elixir, :ebin) + + [path] + |> Protocol.extract_protocols() + |> Enum.all?(&Protocol.consolidated?/1) + end end