From 525a801d22b9fb6272cc64cbba452916d96e9228 Mon Sep 17 00:00:00 2001 From: Tobias Pfeiffer Date: Thu, 11 Apr 2019 19:17:12 +0200 Subject: [PATCH] Adopt benchee 1.0 and work around dependency problems (#74) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Best solution I know for the "benchee depends on Jason" problem is a small separate mix project. I do the same in deep_merge and it works out fine. Only downgrade right now is that you have to do cd `bench` and then `mix bench.encode` - I suspect we can make it work without didn't look it up because I assume MichaƂ would know right away either way :) Happy benchmarking! --- .gitignore | 6 +++++- README.md | 4 ++-- bench/decode.exs | 9 ++------- bench/encode.exs | 9 ++------- bench/mix.exs | 36 ++++++++++++++++++++++++++++++++++++ bench/mix.lock | 14 ++++++++++++++ mix.exs | 18 +----------------- mix.lock | 10 ---------- 8 files changed, 62 insertions(+), 44 deletions(-) create mode 100644 bench/mix.exs create mode 100644 bench/mix.lock diff --git a/.gitignore b/.gitignore index 8862a6f..84ccc4e 100644 --- a/.gitignore +++ b/.gitignore @@ -21,4 +21,8 @@ erl_crash.dump # Ignore benchmark output /bench/output -/bench/snapshots \ No newline at end of file +/bench/snapshots + +# Ignore benchmark specific dependencies etc (separate project to work around problems with dependencies) +/bench/_build +/bench/deps \ No newline at end of file diff --git a/README.md b/README.md index 7a57dec..17504d4 100644 --- a/README.md +++ b/README.md @@ -116,8 +116,8 @@ http://michal.muskala.eu/jason/decode.html and http://michal.muskala.eu/jason/en ### Running -Benchmarks against most popular Elixir & Erlang json libraries can be executed -with `mix bench.encode` and `mix bench.decode`. +Benchmarks against most popular Elixir & Erlang json libraries can be executed after +going into the `bench/` folder and then executing `mix bench.encode` and `mix bench.decode`. A HTML report of the benchmarks (after their execution) can be found in `bench/output/encode.html` and `bench/output/decode.html` respectively. diff --git a/bench/decode.exs b/bench/decode.exs index fa08dcc..bcbbf7d 100644 --- a/bench/decode.exs +++ b/bench/decode.exs @@ -44,12 +44,7 @@ Benchee.run(decode_jobs, memory_time: 1, inputs: inputs, formatters: [ - &Benchee.Formatters.HTML.output/1, - &Benchee.Formatters.Console.output/1, - ], - formatter_options: [ - html: [ - file: Path.expand("output/decode.html", __DIR__) - ] + {Benchee.Formatters.HTML, file: Path.expand("output/decode.html", __DIR__)}, + Benchee.Formatters.Console, ] ) diff --git a/bench/encode.exs b/bench/encode.exs index 7bbcce3..003e449 100644 --- a/bench/encode.exs +++ b/bench/encode.exs @@ -44,12 +44,7 @@ Benchee.run(encode_jobs, |> (&{name, &1}).() end, formatters: [ - &Benchee.Formatters.HTML.output/1, - &Benchee.Formatters.Console.output/1, - ], - formatter_options: [ - html: [ - file: Path.expand("output/encode.html", __DIR__) - ] + {Benchee.Formatters.HTML, file: Path.expand("output/encode.html", __DIR__)}, + Benchee.Formatters.Console ] ) diff --git a/bench/mix.exs b/bench/mix.exs new file mode 100644 index 0000000..7f53b0e --- /dev/null +++ b/bench/mix.exs @@ -0,0 +1,36 @@ +defmodule JasonBench.MixProject do + use Mix.Project + + def project do + [ + app: :jason_bench, + version: "0.1.0", + elixir: "~> 1.6", + start_permanent: Mix.env() == :prod, + deps: deps(), + aliases: aliases() + ] + end + + defp aliases() do + [ + "bench.encode": ["run encode.exs"], + "bench.decode": ["run decode.exs"] + ] + end + + # Run "mix help deps" to learn about dependencies. + defp deps do + [ + {:jason, "~> 1.0", path: "../", override: true}, + {:benchee, "~> 1.0"}, + {:benchee_html, "~> 1.0"}, + {:poison, "~> 3.0"}, + {:exjsx, "~> 4.0"}, + {:tiny, "~> 1.0"}, + {:jsone, "~> 1.4"}, + {:jiffy, "~> 0.14"}, + {:json, "~> 1.0"}, + ] + end +end diff --git a/bench/mix.lock b/bench/mix.lock new file mode 100644 index 0000000..7e4827e --- /dev/null +++ b/bench/mix.lock @@ -0,0 +1,14 @@ +%{ + "benchee": {:hex, :benchee, "1.0.0", "2524b6c0e541309d969accf75f77e1d1653e46142afc68e9ea4ff35559a794bc", [:mix], [{:deep_merge, "~> 1.0", [hex: :deep_merge, repo: "hexpm", optional: false]}], "hexpm"}, + "benchee_html": {:hex, :benchee_html, "1.0.0", "5b4d24effebd060f466fb460ec06576e7b34a00fc26b234fe4f12c4f05c95947", [:mix], [{:benchee, ">= 0.99.0 and < 2.0.0", [hex: :benchee, repo: "hexpm", optional: false]}, {:benchee_json, "~> 1.0", [hex: :benchee_json, repo: "hexpm", optional: false]}], "hexpm"}, + "benchee_json": {:hex, :benchee_json, "1.0.0", "cc661f4454d5995c08fe10dd1f2f72f229c8f0fb1c96f6b327a8c8fc96a91fe5", [:mix], [{:benchee, ">= 0.99.0 and < 2.0.0", [hex: :benchee, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm"}, + "deep_merge": {:hex, :deep_merge, "1.0.0", "b4aa1a0d1acac393bdf38b2291af38cb1d4a52806cf7a4906f718e1feb5ee961", [:mix], [], "hexpm"}, + "exjsx": {:hex, :exjsx, "4.0.0", "60548841e0212df401e38e63c0078ec57b33e7ea49b032c796ccad8cde794b5c", [:mix], [{:jsx, "~> 2.8.0", [hex: :jsx, repo: "hexpm", optional: false]}], "hexpm"}, + "jason": {:hex, :jason, "1.1.2", "b03dedea67a99223a2eaf9f1264ce37154564de899fd3d8b9a21b1a6fd64afe7", [], [{:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm"}, + "jiffy": {:hex, :jiffy, "0.15.2", "de266c390111fd4ea28b9302f0bc3d7472468f3b8e0aceabfbefa26d08cd73b7", [:rebar3], [], "hexpm"}, + "json": {:hex, :json, "1.2.1", "21e8d6983091660f394f44a7c11f8cf1f467afb2aada1fcf59c2f1b590a42f68", [:mix], [], "hexpm"}, + "jsone": {:hex, :jsone, "1.4.7", "a970c23d9700ae7842b526c57677e6e3f10894b429524696ead547e9302391c0", [:rebar3], [], "hexpm"}, + "jsx": {:hex, :jsx, "2.8.3", "a05252d381885240744d955fbe3cf810504eb2567164824e19303ea59eef62cf", [:mix, :rebar3], [], "hexpm"}, + "poison": {:hex, :poison, "3.1.0", "d9eb636610e096f86f25d9a46f35a9facac35609a7591b3be3326e99a0484665", [:mix], [], "hexpm"}, + "tiny": {:hex, :tiny, "1.0.1", "535ea7e600cb1c6ba17b53029266d9d7ec54ce29bfb05d906c433907acfa01ca", [:mix], [], "hexpm"}, +} diff --git a/mix.exs b/mix.exs index ede0233..d8e438c 100644 --- a/mix.exs +++ b/mix.exs @@ -11,8 +11,7 @@ defmodule Jason.Mixfile do start_permanent: Mix.env() == :prod, consolidate_protocols: Mix.env() != :test, deps: deps(), - aliases: aliases(), - preferred_cli_env: ["bench.encode": :bench, "bench.decode": :bench, docs: :docs], + preferred_cli_env: [docs: :docs], dialyzer: dialyzer(), description: description(), package: package(), @@ -29,14 +28,6 @@ defmodule Jason.Mixfile do defp deps() do [ {:decimal, "~> 1.0", optional: true}, - {:benchee, "~> 0.8", only: :bench}, - {:benchee_html, "~> 0.1", only: :bench, github: "michalmuskala/benchee_html"}, - {:poison, "~> 3.0", only: :bench}, - {:exjsx, "~> 4.0", only: :bench}, - {:tiny, "~> 1.0", only: :bench}, - {:jsone, "~> 1.4", only: :bench}, - {:jiffy, "~> 0.14", only: :bench}, - {:json, "~> 1.0", only: :bench}, {:dialyxir, "~> 0.5", only: [:dev, :test], runtime: false}, {:ex_doc, "~> 0.18", only: :docs}, ] ++ maybe_stream_data() @@ -50,13 +41,6 @@ defmodule Jason.Mixfile do end end - defp aliases() do - [ - "bench.encode": ["run bench/encode.exs"], - "bench.decode": ["run bench/decode.exs"] - ] - end - defp dialyzer() do [ ignore_warnings: "dialyzer.ignore" diff --git a/mix.lock b/mix.lock index 0390d62..4be5666 100644 --- a/mix.lock +++ b/mix.lock @@ -1,20 +1,10 @@ %{ - "benchee": {:hex, :benchee, "0.13.1", "bd93ca05be78bcb6159c7176230efeda2f724f7ffd485515175ca411dff4893e", [:mix], [{:deep_merge, "~> 0.1", [hex: :deep_merge, repo: "hexpm", optional: false]}], "hexpm"}, - "benchee_html": {:git, "https://github.com/michalmuskala/benchee_html.git", "e3f60b891b115dd599c9387637e4c36cc0269d7d", []}, "decimal": {:hex, :decimal, "1.5.0", "b0433a36d0e2430e3d50291b1c65f53c37d56f83665b43d79963684865beab68", [:mix], [], "hexpm"}, - "deep_merge": {:hex, :deep_merge, "0.1.1", "c27866a7524a337b6a039eeb8dd4f17d458fd40fbbcb8c54661b71a22fffe846", [:mix], [], "hexpm"}, "dialyxir": {:hex, :dialyxir, "0.5.1", "b331b091720fd93e878137add264bac4f644e1ddae07a70bf7062c7862c4b952", [:mix], [], "hexpm"}, "earmark": {:hex, :earmark, "1.2.6", "b6da42b3831458d3ecc57314dff3051b080b9b2be88c2e5aa41cd642a5b044ed", [:mix], [], "hexpm"}, "ex_doc": {:hex, :ex_doc, "0.19.1", "519bb9c19526ca51d326c060cb1778d4a9056b190086a8c6c115828eaccea6cf", [:mix], [{:earmark, "~> 1.1", [hex: :earmark, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.7", [hex: :makeup_elixir, repo: "hexpm", optional: false]}], "hexpm"}, - "exjsx": {:hex, :exjsx, "4.0.0", "60548841e0212df401e38e63c0078ec57b33e7ea49b032c796ccad8cde794b5c", [:mix], [{:jsx, "~> 2.8.0", [hex: :jsx, repo: "hexpm", optional: false]}], "hexpm"}, - "jiffy": {:hex, :jiffy, "0.15.2", "de266c390111fd4ea28b9302f0bc3d7472468f3b8e0aceabfbefa26d08cd73b7", [:rebar3], [], "hexpm"}, - "json": {:hex, :json, "1.0.3", "547d58dbbd864c0a560c0ca3789ee8848974e8c517cdb7827c3303e3b42e754d", [:mix], [], "hexpm"}, - "jsone": {:hex, :jsone, "1.4.6", "644d6d57befb22c8e19b324dee19d73b1c004565009861a8f64c68b7b9e64dbf", [:rebar3], [], "hexpm"}, - "jsx": {:hex, :jsx, "2.8.3", "a05252d381885240744d955fbe3cf810504eb2567164824e19303ea59eef62cf", [:mix, :rebar3], [], "hexpm"}, "makeup": {:hex, :makeup, "0.5.5", "9e08dfc45280c5684d771ad58159f718a7b5788596099bdfb0284597d368a882", [:mix], [{:nimble_parsec, "~> 0.4", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm"}, "makeup_elixir": {:hex, :makeup_elixir, "0.10.0", "0f09c2ddf352887a956d84f8f7e702111122ca32fbbc84c2f0569b8b65cbf7fa", [:mix], [{:makeup, "~> 0.5.5", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm"}, "nimble_parsec": {:hex, :nimble_parsec, "0.4.0", "ee261bb53214943679422be70f1658fff573c5d0b0a1ecd0f18738944f818efe", [:mix], [], "hexpm"}, - "poison": {:hex, :poison, "3.1.0", "d9eb636610e096f86f25d9a46f35a9facac35609a7591b3be3326e99a0484665", [:mix], [], "hexpm"}, "stream_data": {:hex, :stream_data, "0.4.2", "fa86b78c88ec4eaa482c0891350fcc23f19a79059a687760ddcf8680aac2799b", [:mix], [], "hexpm"}, - "tiny": {:hex, :tiny, "1.0.1", "535ea7e600cb1c6ba17b53029266d9d7ec54ce29bfb05d906c433907acfa01ca", [:mix], [], "hexpm"}, }