Powered by AppSignal & Oban Pro
Would you like to see your link here? Contact us

BencheeDsl example

example.livemd

BencheeDsl example

Mix.install([
  {:benchee_dsl, "0.5.1"},
  {:benchee_markdown, "~> 0.3"}
])

flat-map vs map-flatten

{:module, name, _binary, _bindings} =
  defmodule Benchmark do
    use BencheeDsl.Benchmark

    config(
      warmup: 1,
      time: 1,
      memory_time: 1,
      reduction_time: 1,
      print: [configuration: false, benchmarking: false]
    )

    inputs(%{"Small" => Enum.to_list(1..1000), "Big" => Enum.to_list(1..100_000)})

    defp map_fun(i) do
      [i, i * i]
    end

    job(flat_map(input)) do
      Enum.flat_map(input, &map_fun/1)
    end

    job(map_flatten(input)) do
      input |> Enum.map(&map_fun/1) |> List.flatten()
    end
  end

BencheeDsl.Livebook.benchee_config() |> name.run() |> BencheeDsl.Livebook.render()