Skip to content

Commit

Permalink
Performance improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
devinus committed Jun 25, 2021
1 parent 1eed4de commit 2da7814
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 126 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ poison-*.tar
/tmp

.elixir_ls
*.benchee
/bench/output/
15 changes: 4 additions & 11 deletions bench/run.exs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ defmodule Bench do
time: 10,
memory_time: 1,
pre_check: true,
load: Path.join(__DIR__, "decode.benchee"),
save: [path: Path.join(__DIR__, "decode.benchee")],
inputs:
for name <- decode_inputs(), into: %{} do
name
|> read_data()
|> (&{name, &1}).()
end,
before_each: fn input -> :binary.copy(input) end,
after_scenario: fn _input -> gc() end,
formatters: [
{Console, extended_statistics: true},
{HTML, extended_statistics: true, file: Path.expand("output/decode.html", __DIR__)}
Expand All @@ -30,30 +31,22 @@ defmodule Bench do
time: 10,
memory_time: 1,
pre_check: true,
load: Path.join(__DIR__, "encode.benchee"),
save: [path: Path.join(__DIR__, "encode.benchee")],
inputs:
for name <- encode_inputs(), into: %{} do
name
|> read_data()
|> Poison.decode!()
|> (&{name, &1}).()
end,
after_scenario: fn _input -> gc() end,
formatters: [
{Console, extended_statistics: true},
{HTML, extended_statistics: true, file: Path.expand("output/encode.html", __DIR__)}
]
)
end

defp gc do
request_id = System.monotonic_time()
:erlang.garbage_collect(self(), async: request_id)

receive do
{:garbage_collect, ^request_id, _dead} -> :ok
end
end

defp read_data(name) do
name
|> String.downcase()
Expand Down
Loading

0 comments on commit 2da7814

Please sign in to comment.