Skip to content

Commit

Permalink
Righty, forgot to only scrubt the suite when parallel processing
Browse files Browse the repository at this point in the history
Now, that scenario is finally fast/fastest in that lil benchmark:

```
Name                        ips        average  deviation         median         99th %
Formatter.output         248.71        4.02 ms     ±4.58%        4.03 ms        4.59 ms
sequential_output        248.38        4.03 ms     ±3.16%        4.00 ms        4.53 ms
format & write           247.77        4.04 ms     ±6.76%        4.02 ms        4.35 ms

Comparison:
Formatter.output         248.71
sequential_output        248.38 - 1.00x slower +0.00539 ms
format & write           247.77 - 1.00x slower +0.0153 ms
```
  • Loading branch information
PragTob committed Dec 14, 2023
1 parent 40b7d4a commit 5a8fda1
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions lib/benchee/formatter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -153,23 +153,30 @@ defmodule Benchee.Formatter do
# in parallel at all to avoid the cost of copying all the data to a new process
# (and of us scrubbing it so we don't need as much data)
defp maybe_parallel_output(suite, module_configurations) do
scrubbed_suite = scrub_suite(suite)

module_configurations
|> maybe_parallel_map(fn {module, options} ->
{module, options, module.format(scrubbed_suite, options)}
end)
|> maybe_parallel_format(suite)
|> Enum.each(fn {module, options, output} -> module.write(output, options) end)

suite
end

defp maybe_parallel_map([_one_element] = list, function) do
Enum.map(list, function)
# don't let it drop to the `Parallel` case so we don't do the scrubbing
# for nothing
defp maybe_parallel_format([], _suite), do: []

defp maybe_parallel_format(formatters = [_one_formatter], suite) do
Enum.map(formatters, fn {module, options} ->
{module, options, module.format(suite, options)}
end)
end

defp maybe_parallel_map(list, function) do
Parallel.map(list, function)
defp maybe_parallel_format(formatters, suite) do
# suite only needs scrubbing for parallel processing due to data copying
scrubbed_suite = scrub_suite(suite)

Parallel.map(formatters, fn {module, options} ->
{module, options, module.format(scrubbed_suite, options)}
end)
end

# The actual benchmarking functions and the actual inputs should not be important for
Expand Down

0 comments on commit 5a8fda1

Please sign in to comment.