Skip to content

Instantly share code, notes, and snippets.

@philss
Created March 17, 2022 17:40
Show Gist options
  • Save philss/1211fb82d108bd21cffb217ed5dc968c to your computer and use it in GitHub Desktop.
Save philss/1211fb82d108bd21cffb217ed5dc968c to your computer and use it in GitHub Desktop.
Compare from_list/1 and from_map/1

Benchmark Explorer.DataFrame.from_list/1

Deps

Mix.install([
  {:benchee, "~> 1.0.0"},
  {:explorer, github: "kimjoaoun/explorer", branch: "joao/from_list"}
])

Benchmark

example = [
  %{id: 1, name: "José"},
  %{id: 2, name: "Christopher"},
  %{id: 3, name: "Cristine"},
  %{id: 4, name: "João"},
  %{id: 5, name: "Philip"},
  %{id: 6, name: "Jonatan"},
  %{id: 7, name: "Wojtek"}
]

example_map = %{
  id: Enum.map(example, &Map.fetch!(&1, :id)),
  name: Enum.map(example, &Map.fetch!(&1, :name))
}

Benchee.run(
  %{
    "from_list" => fn -> Explorer.DataFrame.from_list(example) end,
    "from_map" => fn -> Explorer.DataFrame.from_map(example_map) end
  },
  time: 10,
  memory_time: 2
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment