Skip to content

Instantly share code, notes, and snippets.

@Qqwy
Created September 6, 2021 22:47
Show Gist options
  • Save Qqwy/466b4b635e0de0e51122ed9976bd73f5 to your computer and use it in GitHub Desktop.
Save Qqwy/466b4b635e0de0e51122ed9976bd73f5 to your computer and use it in GitHub Desktop.
defmodule Benchmarks do
@warmup 0.05
@time 0.05
@memory_time 0.5
@parallel 1
@inputs (
(0..20)
|> Enum.map(fn size -> {to_string(size), (1..size) |> Enum.shuffle |> List.to_tuple} end)
)
def run() do
Benchee.run(
%{
"map_tuple/2" =>
fn input ->
TupleMap.map_tuple(input, &(&1 * 2))
end,
"map through list" =>
fn input ->
TupleMap.map_tuple_through_list(input, &(&1 * 2))
end},
after_each: fn _ -> :erlang.garbage_collect() end,
inputs: @inputs,
warmup: @warmup,
time: @time,
memory_time: @memory_time,
parallel: @parallel,
pre_check: true,
formatters: [
Benchee.Formatters.Console,
{Benchee.Formatters.CSV, file: "benchmark_runs/map_integer_mult.csv"},
{Benchee.Formatters.HTML, file: "benchmark_runs/map_integer_mult.html", auto_open: false},
{Benchee.Formatters.Markdown, file: "benchmark_runs/map_integer_mult.md", description: """
Compares the function `x * 2`
between mapping a function over all elements of a tuple,
vs. turning the tuple into a list first, then mapping over that list, and turning the list back.
"""
}
]
)
end
end
Benchmarks.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment