Microbenchmarking elixir with Benchee
There is a hex package to help facilitate benchmarking in elixir. Below is an example of how to compare flat_map
to map().flatten()
. Example stolen straight from the README.
list = Enum.to_list(1..10_000)
map_fun = fn(i) -> [i, i * i] end
Benchee.run(%{time: 3},
[{"flat_map", fn -> Enum.flat_map(list, map_fun) end},
{"map.flatten",
fn -> list |> Enum.map(map_fun) |> List.flatten end}])
Tweet