   ```
 
   """
-  @spec format_scenarios([Scenario.t], map) :: [String.t, ...]
+  @spec format_scenarios([Scenario.t()], map) :: [String.t(), ...]
   def format_scenarios(scenarios, config) do
     sorted_scenarios = Statistics.sort(scenarios)
     %{unit_scaling: scaling_strategy} = config
     units = Conversion.units(sorted_scenarios, scaling_strategy)
     label_width = label_width(sorted_scenarios)
 
-    [column_descriptors(label_width) |
-      scenario_reports(sorted_scenarios, units, label_width)
-      ++ comparison_report(sorted_scenarios, units, label_width, config)
-      ++ extended_statistics_report(
-          sorted_scenarios, units, label_width, config)]
-  end
-
-  @spec extended_statistics_report(
-    [Scenario.t], unit_per_statistic, integer, map) :: [String.t]
+    [
+      column_descriptors(label_width)
+      | scenario_reports(sorted_scenarios, units, label_width) ++
+          comparison_report(sorted_scenarios, units, label_width, config) ++
+          extended_statistics_report(sorted_scenarios, units, label_width, config)
+    ]
+  end
+
+
+  def format_scenarios_for_memory(scenarios, config) do
+    sorted_scenarios = Statistics.sort(scenarios)
+    #%{unit_scaling: scaling_strategy} = config
+    units = %{memory: %Unit{label: "b", long: "byte", magnitude: 1, name: :byte}}
+    label_width = label_width(sorted_scenarios)
+
+    [
+      column_descriptors_for_memory(label_width)
+      | scenario_reports_for_memory(sorted_scenarios, units, label_width) ++
+          comparison_report_for_memory(sorted_scenarios, units, label_width, config) ++
+          extended_statistics_report(sorted_scenarios, units, label_width, config)
+    ]
+  end
+
+  @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)
+      extended_column_descriptors(label_width)
+      | extended_statistics(scenarios, units, label_width)
     ]
   end
 
-  @spec extended_statistics([Scenario.t], unit_per_statistic, integer)
-    :: [String.t]
+  @spec extended_statistics([Scenario.t()], unit_per_statistic, integer) :: [String.t()]
   defp extended_statistics(scenarios, units, label_width) do
-    Enum.map(scenarios, fn(scenario) ->
+    Enum.map(scenarios, fn scenario ->
       format_scenario_extended(scenario, units, label_width)
     end)
   end
 
-  @spec format_scenario_extended(Scenario.t, unit_per_statistic, integer)
-    :: String.t
-  defp format_scenario_extended(%Scenario{
-                                  name: name,
-                                  run_time_statistics: %Statistics{
-                                    minimum:     minimum,
-                                    maximum:     maximum,
-                                    sample_size: sample_size,
-                                    mode:        mode
-                                  }
-                                },
-                                %{run_time: run_time_unit},
-                                label_width) do
+  @spec format_scenario_extended(Scenario.t(), unit_per_statistic, integer) :: String.t()
+  defp format_scenario_extended(
+         %Scenario{
+           name: name,
+           run_time_statistics: %Statistics{
+             minimum: minimum,
+             maximum: maximum,
+             sample_size: sample_size,
+             mode: mode
+           }
+         },
+         %{run_time: run_time_unit},
+         label_width
+       ) do
     "~*s~*ts~*ts~*ts~*ts\n"
     |> :io_lib.format([
-      -label_width, name,
-      @minimum_width, run_time_out(minimum, run_time_unit),
-      @maximum_width, run_time_out(maximum, run_time_unit),
-      @sample_size_width, Count.format(sample_size),
-      @mode_width, mode_out(mode, run_time_unit)])
-    |> to_string
-  end
-
-  @spec mode_out(Statistics.mode, Benchee.Conversion.Unit.t) :: String.t
+      -label_width,
+      name,
+      @minimum_width,
+      run_time_out(minimum, run_time_unit),
+      @maximum_width,
+      run_time_out(maximum, run_time_unit),
+      @sample_size_width,
+      Count.format(sample_size),
+      @mode_width,
+      mode_out(mode, run_time_unit)
+    ])
+    |> to_string
+  end
+
+  @spec mode_out(Statistics.mode(), 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
+    Enum.map_join(modes, ", ", fn mode -> run_time_out(mode, run_time_unit) end)
+  end
+
   defp mode_out(mode, run_time_unit) when is_number(mode) do
     run_time_out(mode, run_time_unit)
   end
 
-  @spec extended_column_descriptors(integer) :: String.t
+  @spec extended_column_descriptors(integer) :: String.t()
   defp extended_column_descriptors(label_width) do
     "\n~*s~*s~*s~*s~*s\n"
-    |> :io_lib.format([-label_width, "Name", @minimum_width, "minimum",
-                       @maximum_width, "maximum", @sample_size_width, "sample size",
-                       @mode_width, "mode"])
-    |> to_string
-  end
-
-  @spec column_descriptors(integer) :: String.t
+    |> :io_lib.format([
+      -label_width,
+      "Name",
+      @minimum_width,
+      "minimum",
+      @maximum_width,
+      "maximum",
+      @sample_size_width,
+      "sample size",
+      @mode_width,
+      "mode"
+    ])
+    |> to_string
+  end
+
+  @spec column_descriptors(integer) :: String.t()
   defp column_descriptors(label_width) do
     "\n~*s~*s~*s~*s~*s~*s\n"
-    |> :io_lib.format([-label_width, "Name", @ips_width, "ips",
-                       @average_width, "average",
-                       @deviation_width, "deviation", @median_width, "median",
-                       @percentile_width, "99th %"])
+    |> :io_lib.format([
+      -label_width,
+      "Name",
+      @ips_width,
+      "ips",
+      @average_width,
+      "average",
+      @deviation_width,
+      "deviation",
+      @median_width,
+      "median",
+      @percentile_width,
+      "99th %"
+    ])
+    |> to_string
+  end
+
+  defp column_descriptors_for_memory(label_width) do
+    "\n~*s~*s~*s~*s~*s\n"
+    |> :io_lib.format([
+      -label_width,
+      "Name",
+      @average_width,
+      "average",
+      @deviation_width,
+      "deviation",
+      @median_width,
+      "median",
+      @percentile_width,
+      "99th %"
+    ])
     |> to_string
   end
 
   defp label_width(scenarios) do
     max_label_width =
       scenarios
-      |> Enum.map(fn(scenario) -> String.length(scenario.name) end)
+      |> Enum.map(fn scenario -> String.length(scenario.name) end)
       |> Stream.concat([@default_label_width])
-      |> Enum.max
+      |> Enum.max()
+
     max_label_width + 1
   end
 
-  @spec scenario_reports([Scenario.t], unit_per_statistic, integer)
-    :: [String.t]
+  @spec scenario_reports([Scenario.t()], unit_per_statistic, integer) :: [String.t()]
   defp scenario_reports(scenarios, units, label_width) do
-    Enum.map(scenarios, fn(scenario) ->
+    Enum.map(scenarios, fn scenario ->
       format_scenario(scenario, units, label_width)
     end)
   end
 
-  @spec format_scenario(Scenario.t, unit_per_statistic, integer) :: String.t
-  defp format_scenario(%Scenario{
-                         name: name,
-                         run_time_statistics: %Statistics{
-                           average:       average,
-                           ips:           ips,
-                           std_dev_ratio: std_dev_ratio,
-                           median:        median,
-                           percentiles:   %{99 => percentile_99}
-                         }
-                       },
-                       %{run_time: run_time_unit,
-                         ips:      ips_unit,
-                       }, label_width) do
+  defp scenario_reports_for_memory(scenarios, units, label_width) do
+    Enum.map(scenarios, fn scenario ->
+      format_scenario_for_memory(scenario, units, label_width)
+    end)
+  end
+
+  @spec format_scenario(Scenario.t(), unit_per_statistic, integer) :: String.t()
+  defp format_scenario(
+         %Scenario{
+           name: name,
+           run_time_statistics: %Statistics{
+             average: average,
+             ips: ips,
+             std_dev_ratio: std_dev_ratio,
+             median: median,
+             percentiles: %{99 => percentile_99}
+           }
+         },
+         %{run_time: run_time_unit, ips: ips_unit},
+         label_width
+       ) do
     "~*s~*ts~*ts~*ts~*ts~*ts\n"
     |> :io_lib.format([
-      -label_width, name,
-      @ips_width, ips_out(ips, ips_unit),
-      @average_width, run_time_out(average, run_time_unit),
-      @deviation_width, deviation_out(std_dev_ratio),
-      @median_width, run_time_out(median, run_time_unit),
-      @percentile_width, run_time_out(percentile_99, run_time_unit)])
+      -label_width,
+      name,
+      @ips_width,
+      ips_out(ips, ips_unit),
+      @average_width,
+      run_time_out(average, run_time_unit),
+      @deviation_width,
+      deviation_out(std_dev_ratio),
+      @median_width,
+      run_time_out(median, run_time_unit),
+      @percentile_width,
+      run_time_out(percentile_99, run_time_unit)
+    ])
+    |> to_string
+  end
+
+  defp format_scenario_for_memory(
+         %Scenario{
+           name: name,
+           memory_usage_statistics: %Statistics{
+             average: average,
+             std_dev_ratio: std_dev_ratio,
+             median: median,
+             percentiles: %{99 => percentile_99}
+           }
+         },
+         %{memory: memory_unit},
+         label_width
+       ) do
+    "~*ts~*ts~*ts~*ts~*ts\n"
+    |> :io_lib.format([
+      -label_width,
+      name,
+      @average_width,
+      run_time_out(average, memory_unit),
+      @deviation_width,
+      deviation_out(std_dev_ratio),
+      @median_width,
+      run_time_out(median, memory_unit),
+      @percentile_width,
+      run_time_out(percentile_99, memory_unit)
+    ])
     |> to_string
   end
 

  use Benchee.Formatter

  alias Benchee.{
    Statistics, Suite, Benchmark.Scenario, Configuration, Conversion
  }
  alias Benchee.Conversion.{Count, Duration, Unit, DeviationPercent}

  @type unit_per_statistic :: %{atom => Unit.t}

  @default_label_width 4 # Length of column header
  @ips_width 13
  @average_width 15
  @deviation_width 11

  end

  defp console_configuration(%Configuration{
         formatter_options: %{console: config},
         unit_scaling: scaling_strategy
       }) do
    if Map.has_key?(config, :unit_scaling), do: warn_unit_scaling()
    Map.put(config, :unit_scaling, scaling_strategy)
  end

  defp warn_unit_scaling do
    IO.puts(
      "unit_scaling is now a top level configuration option, avoid passing it as a formatter option."
    )
  end

  @no_input_marker Benchee.Benchmark.no_input()
  defp input_header(input) do
    case input do
      @no_input_marker -> ""
      _ -> "\n##### With input #{input} #####"
    end
  end

