Commit 9d58da4a authored by rinpatch's avatar rinpatch

Move benchmark to a separate env and don't include fixtures in hex

Closes #4
parent fb028f13
Pipeline #19755 passed with stage
in 1 minute and 36 seconds
defmodule Mix.Tasks.FastHtml.Bench do
@moduledoc "Benchmarking task."
if Mix.env() == :bench do
defmodule Mix.Tasks.FastHtml.Bench do
@moduledoc "Benchmarking task."
use Mix.Task
use Mix.Task
@input_dir "lib/mix/tasks/fast_html/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(
%{
"fast_html" => fn input -> :fast_html.decode(input) end,
"myhtmlex nif" => fn input -> Myhtmlex.Nif.decode(input) end,
"html5ever nif" => fn input -> Html5ever.parse(input) end,
"mochiweb_html" => fn input -> :mochiweb_html.parse(input) end
},
inputs: inputs,
save: [path: "fast_html.bench"],
load: "fast_html.bench"
)
Benchee.run(
%{
"fast_html" => fn input -> :fast_html.decode(input) end,
"myhtmlex nif" => fn input -> Myhtmlex.Nif.decode(input) end,
"html5ever nif" => fn input -> Html5ever.parse(input) end,
"mochiweb_html" => fn input -> :mochiweb_html.parse(input) end
},
inputs: inputs,
save: [path: "fast_html.bench"],
load: "fast_html.bench"
)
end
end
end
......@@ -4,7 +4,7 @@ defmodule FastHtml.Mixfile do
def project do
[
app: :fast_html,
version: "0.99.2",
version: "0.99.3",
elixir: "~> 1.5",
deps: deps(),
package: package(),
......@@ -67,10 +67,10 @@ defmodule FastHtml.Mixfile do
# documentation helpers
{:ex_doc, "~> 0.19", only: :dev},
# benchmarking helpers
{:benchee, "~> 1.0", only: :dev, optional: true},
{:myhtmlex, "~> 0.2.0", only: :dev, runtime: false, optional: true},
{:mochiweb, "~> 2.18", only: :dev, optional: true},
{:html5ever, "~> 0.7.0", only: :dev, optional: true}
{:benchee, "~> 1.0", only: :bench, optional: true},
{:myhtmlex, "~> 0.2.0", only: :bench, runtime: false, optional: true},
{:mochiweb, "~> 2.18", only: :bench, optional: true},
{:html5ever, "~> 0.7.0", only: :bench, optional: true}
]
end
......
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