Commit 8a7ba442 authored by rinpatch's avatar rinpatch

Have a separate env for benchmarks and move fixtures into a directory

not included in hex
parent ea26f503
Pipeline #19751 passed with stage
in 1 minute and 33 seconds
defmodule Mix.Tasks.FastSanitize.Bench do
@moduledoc "Benchmarking task."
if Mix.env() == :bench do
defmodule Mix.Tasks.FastSanitize.Bench do
@moduledoc "Benchmarking task."
use Mix.Task
use Mix.Task
@input_dir "lib/mix/tasks/fast_sanitize/html"
@input_dir "bench_fixtures"
def run(_) do
Application.ensure_all_started(:fast_html)
def run(_) do
Application.ensure_all_started(:fast_html)
inputs =
Enum.reduce(File.ls!(@input_dir), %{}, fn input_name, acc ->
input = File.read!(Path.join(@input_dir, input_name))
Map.put(acc, input_name, input)
end)
inputs =
Enum.reduce(File.ls!(@input_dir), %{}, fn input_name, acc ->
input = File.read!(Path.join(@input_dir, input_name))
Map.put(acc, input_name, input)
end)
Benchee.run(
%{
"FastSanitize strip tags" => fn input -> FastSanitize.strip_tags(input) end,
"HtmlSanitizeex strip tags" => fn input -> HtmlSanitizeEx.strip_tags(input) end,
"FastSanitize basic html" => fn input -> FastSanitize.basic_html(input) end,
"HtmlSanitizeex basic html" => fn input -> HtmlSanitizeEx.basic_html(input) end
},
inputs: inputs
)
Benchee.run(
%{
"FastSanitize strip tags" => fn input -> FastSanitize.strip_tags(input) end,
"HtmlSanitizeex strip tags" => fn input -> HtmlSanitizeEx.strip_tags(input) end,
"FastSanitize basic html" => fn input -> FastSanitize.basic_html(input) end,
"HtmlSanitizeex basic html" => fn input -> HtmlSanitizeEx.basic_html(input) end
},
inputs: inputs
)
end
end
end
......@@ -40,8 +40,8 @@ defmodule FastSanitize.MixProject do
{:plug, "~> 1.8"},
{:fast_html, "~> 0.99"},
{:credo, "~> 1.0.0", only: [:dev, :test], runtime: false},
{:benchee, "~> 1.0", only: :dev},
{:html_sanitize_ex, "~> 1.3.0-rc3", only: :dev},
{:benchee, "~> 1.0", only: :bench},
{:html_sanitize_ex, "~> 1.3.0-rc3", only: :bench},
{:ex_doc, "~> 0.19", only: :dev, runtime: false},
{:dialyxir, "~> 1.0.0-rc.5", only: [:dev], runtime: false}
]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment