Skip to content

Instantly share code, notes, and snippets.

@mkumm
Created February 17, 2024 15:01
Show Gist options
  • Save mkumm/911dd1c1cdabd19eba586122396cd684 to your computer and use it in GitHub Desktop.
Save mkumm/911dd1c1cdabd19eba586122396cd684 to your computer and use it in GitHub Desktop.
Livebook - Sample Benchee

Sample Benchee

Mix.install([
  {:benchee, "~> 1.3"}
])

Section

defmodule Bench do
  def run() do
    list = Enum.map(1..10000, fn _ -> :rand.uniform(30000) end)

    Benchee.run(
      %{
        "map then join" => fn -> list |> Enum.map(&Integer.to_string(&1)) |> Enum.join(", ") end,
        "mapjoin" => fn -> list |> Enum.map_join(", ", &Integer.to_string(&1)) end
      },
      time: 10,
      memory_time: 2
    )
  end
end
Bench.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment