Skip to content

Commit

Permalink
credo and format fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
PragTob committed Nov 9, 2023
1 parent f0b847d commit 9890052
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 39 deletions.
4 changes: 1 addition & 3 deletions lib/benchee/formatters/render.ex
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,7 @@ defmodule Benchee.Formatters.HTML.Render do
end

defp format_mode(modes = [_ | _], unit) do
modes
|> Enum.map(fn mode -> format_property(mode, unit) end)
|> Enum.join(", ")
Enum.map_join(modes, ", ", fn mode -> format_property(mode, unit) end)
end

defp format_mode(value, unit) do
Expand Down
11 changes: 6 additions & 5 deletions samples/fast_memory.exs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
list = Enum.to_list(1..10_000)
map_fun = fn(i) -> [i, i * i] end
map_fun = fn i -> [i, i * i] end

Benchee.run(%{
"flat_map" => fn -> Enum.flat_map(list, map_fun) end,
"map.flatten" => fn -> list |> Enum.map(map_fun) |> List.flatten end
},
Benchee.run(
%{
"flat_map" => fn -> Enum.flat_map(list, map_fun) end,
"map.flatten" => fn -> list |> Enum.map(map_fun) |> List.flatten() end
},
formatters: [
{Benchee.Formatters.HTML, file: "samples_output/memory.html"},
Benchee.Formatters.Console
Expand Down
11 changes: 6 additions & 5 deletions samples/fast_memory_changing.exs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
# random by design so that memory actually changes
# this has too wide of a range and too small of a sample size, don't do this at home
Benchee.run(%{
"Enum.to_list" => fn range -> Enum.to_list(range) end,
"Enum.into" => fn range -> Enum.into(range, []) end
},
Benchee.run(
%{
"Enum.to_list" => fn range -> Enum.to_list(range) end,
"Enum.into" => fn range -> Enum.into(range, []) end
},
formatters: [
{Benchee.Formatters.HTML, file: "samples_output/memory_changing.html"},
{Benchee.Formatters.Console, extended_statistics: true}
],
before_each: fn _ -> (0..:rand.uniform(1_000) + 1000) end,
before_each: fn _ -> 0..(:rand.uniform(1_000) + 1000) end,
warmup: 0,
time: 0.1,
memory_time: 0.1
Expand Down
43 changes: 23 additions & 20 deletions samples/many_jobs.exs
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
list_10k = 1..10_000 |> Enum.to_list |> Enum.shuffle
list_30k = 1..30_000 |> Enum.to_list |> Enum.shuffle
list_50k = 1..50_000 |> Enum.to_list |> Enum.shuffle
list_70k = 1..70_000 |> Enum.to_list |> Enum.shuffle
list_90k = 1..90_000 |> Enum.to_list |> Enum.shuffle
list_100k = 1..100_000 |> Enum.to_list |> Enum.shuffle
list_10k = 1..10_000 |> Enum.to_list() |> Enum.shuffle()
list_30k = 1..30_000 |> Enum.to_list() |> Enum.shuffle()
list_50k = 1..50_000 |> Enum.to_list() |> Enum.shuffle()
list_70k = 1..70_000 |> Enum.to_list() |> Enum.shuffle()
list_90k = 1..90_000 |> Enum.to_list() |> Enum.shuffle()
list_100k = 1..100_000 |> Enum.to_list() |> Enum.shuffle()

Benchee.run %{
"10k" => fn -> Enum.sort(list_10k) end,
"30k" => fn -> Enum.sort(list_30k) end,
"50k" => fn -> Enum.sort(list_50k) end,
"70k" => fn -> Enum.sort(list_70k) end,
"90k" => fn -> Enum.sort(list_90k) end,
"100k" => fn -> Enum.sort(list_100k) end,
}, time: 2,
warmup: 0,
unit_scaling: :largest,
formatters: [
Benchee.Formatters.Console,
{Benchee.Formatters.HTML, file: "samples_output/many.html"}
]
Benchee.run(
%{
"10k" => fn -> Enum.sort(list_10k) end,
"30k" => fn -> Enum.sort(list_30k) end,
"50k" => fn -> Enum.sort(list_50k) end,
"70k" => fn -> Enum.sort(list_70k) end,
"90k" => fn -> Enum.sort(list_90k) end,
"100k" => fn -> Enum.sort(list_100k) end
},
time: 2,
warmup: 0,
unit_scaling: :largest,
formatters: [
Benchee.Formatters.Console,
{Benchee.Formatters.HTML, file: "samples_output/many.html"}
]
)
13 changes: 7 additions & 6 deletions samples/multiple_inputs.exs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
map_fun = fn(i) -> [i, i * i] end
map_fun = fn i -> [i, i * i] end

Benchee.run(%{
"flat_map" => fn(list) -> Enum.flat_map(list, map_fun) end,
"map.flatten" => fn(list) -> list |> Enum.map(map_fun) |> List.flatten end
},
Benchee.run(
%{
"flat_map" => fn list -> Enum.flat_map(list, map_fun) end,
"map.flatten" => fn list -> list |> Enum.map(map_fun) |> List.flatten() end
},
formatters: [
{Benchee.Formatters.HTML, file: "samples_output/multiputs.html"},
Benchee.Formatters.Console
Expand All @@ -12,6 +13,6 @@ Benchee.run(%{
warmup: 3,
inputs: %{
"Smaller List" => Enum.to_list(1..1_000),
"Bigger List" => Enum.to_list(1..100_000),
"Bigger List" => Enum.to_list(1..100_000)
}
)

0 comments on commit 9890052

Please sign in to comment.