Skip to content

Instantly share code, notes, and snippets.

@cigrainger
Created March 19, 2022 05:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cigrainger/5ec3e11a2ae952ce36f2fe91b7440a63 to your computer and use it in GitHub Desktop.
Save cigrainger/5ec3e11a2ae952ce36f2fe91b7440a63 to your computer and use it in GitHub Desktop.

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"}
]

Benchee.run(
  %{
    "from_list" => fn -> Explorer.DataFrame.from_list(example) end,
    "from_map" => fn ->
      example_map = %{
        id: Enum.map(example, &Map.fetch!(&1, :id)),
        name: Enum.map(example, &Map.fetch!(&1, :name))
      }

      Explorer.DataFrame.from_map(example_map)
    end
  },
  time: 10,
  memory_time: 2
)
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"}
  ]
  |> List.duplicate(10)
  |> List.flatten()

Benchee.run(
  %{
    "from_list" => fn -> Explorer.DataFrame.from_list(example) end,
    "from_map" => fn ->
      example_map = %{
        id: Enum.map(example, &Map.fetch!(&1, :id)),
        name: Enum.map(example, &Map.fetch!(&1, :name))
      }

      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