Git Product home page Git Product logo

list_of_lists's Introduction

Repository for Zipping a list of lists from the following:

[
  [1,2,3,4],
  ["a","b","c","d"]
]

Into the following format:

[
  [1,"a"],
  [2,"b"],
  [3,"c"],
  [4,"d"],
]

There is Enum.zip(), but this does Tuples.

I also need to use this for a large rowset, where the rowset can be 50-100k+ long with many columns.

The purpose is to convert a columnar based result to a row based result.

mix deps.get
MIX_ENV=prod mix run bench/benchmark.exs
Operating System: Linux
CPU Information: AMD Ryzen 5 5600X 6-Core Processor
Number of Available Cores: 12
Available memory: 31.26 GB
Elixir 1.13.4
Erlang 25.0.1

Benchmark suite executing with the following configuration:
warmup: 2 s
time: 30 s
memory time: 0 ns
reduction time: 0 ns
parallel: 1
inputs: none specified
Estimated total run time: 2.13 min

Benchmarking Converting using Enum.zip ...
Benchmarking Converting using Enum.zip / Enum.map(&Tuple.to_list(&1)) ...
Benchmarking Converting using Enum.zip_reduce ...
Benchmarking Converting using Stream.zip |> Stream.map |> Enum.to_list() ...

Name                                                                  ips        average  deviation         median         99th %
Converting using Enum.zip / Enum.map(&Tuple.to_list(&1))            22.03       45.40 ms    ±45.49%       38.41 ms       77.61 ms
Converting using Enum.zip_reduce                                    21.79       45.89 ms    ±31.63%       35.19 ms       64.20 ms
Converting using Enum.zip                                           17.56       56.95 ms     ±2.56%       56.85 ms       60.67 ms
Converting using Stream.zip |> Stream.map |> Enum.to_list()         14.64       68.29 ms    ±16.42%       68.57 ms       85.17 ms

Comparison: 
Converting using Enum.zip / Enum.map(&Tuple.to_list(&1))            22.03
Converting using Enum.zip_reduce                                    21.79 - 1.01x slower +0.49 ms
Converting using Enum.zip                                           17.56 - 1.25x slower +11.55 ms
Converting using Stream.zip |> Stream.map |> Enum.to_list()         14.64 - 1.50x slower +22.89 ms

list_of_lists's People

Contributors

joshuataylor avatar

Watchers

 avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.