To be fair, :maps.map is the fastest. But it's about as fast as :lists.map . Enum has a lot of overhead.
On Thu, Jul 7, 2016 at 3:23 PM Ben Wilson <[email protected]> wrote: > This is correct. map |> Enum.map(&fun) |> Map.new is the fastest possible > way to take a map and iterate over all of its keys. > > Reason being, building a new list of {k, v} pairs and calling the > `:maps.from_list` NIF always beats out N Map.put calls, which is how into: > %{} works. It also creates less garbage. Map.new is basically just > :maps.from_list if it gets passed a list. > > > On Thursday, July 7, 2016 at 2:48:39 PM UTC-4, Michał Muskała wrote: > >> What do you mean by not converting to a list? >> The fastest way right now of doing a map on a map is actually to convert >> to list, map and convert back to a map. >> I’d suspect that’s the case with a lot of data structures as well, >> actually. Lists are simply really good for recursion. >> The benefit is even greater if you do multiple operations on those lists, >> as the conversion happens (ideally) only >> once. >> >> Michał. >> >> On 07 Jul 2016, at 19:35, Peter Hamilton <[email protected]> wrote: >> >> Does the Enumerable protocol enable the performance improvement of not >> converting to a list? I don't think it does. >> >> On Thu, Jul 7, 2016, 10:24 AM Andrea Leopardi <[email protected]> wrote: >> >> Enum.into/3 should do what you want :) >>> >>> On Thursday, 7 July 2016, Wiebe-Marten Wijnja <[email protected]> >>> wrote: >>> >>>> I propose to add `into: collectable` as optional third argument to >>>> Enum.map. >>>> >>>> This would allow mapping over things without first converting it to a >>>> list and then convert it back. >>>> >>>> So: >>>> >>>> %{"a" => 1, "b" => 2} >>>> |> Enum.map(fn {k, v} -> {String.upcase(k), v} end) >>>> |> Enum.into(%{}) >>>> >>>> could be written as: >>>> >>>> %{"a" => 1, "b" => 2} >>>> |> Enum.map(fn {k, v} -> {String.upcase(k), v} end, into: %{}) >>>> >>>> Not having to do the list conversion in the middle might also improve >>>> performance. >>>> >>>> >>>> Right now, enumerating and collecting in one go is of course possible >>>> using `Kernel.SpecialForms.for`. `for` is however not very >>>> pipeline-friendly. >>>> >>>> >>>> What do you think? >>>> >>>> >>>> Sincerely, >>>> >>>> ~Wiebe-Marten >>>> >>>> -- >>>> You received this message because you are subscribed to the Google >>>> Groups "elixir-lang-core" group. >>>> To unsubscribe from this group and stop receiving emails from it, send >>>> an email to [email protected]. >>>> To view this discussion on the web visit >>>> https://groups.google.com/d/msgid/elixir-lang-core/23c345b9-9ba1-48ea-8db0-6d2e9e700473%40googlegroups.com >>>> <https://groups.google.com/d/msgid/elixir-lang-core/23c345b9-9ba1-48ea-8db0-6d2e9e700473%40googlegroups.com?utm_medium=email&utm_source=footer> >>>> . >>>> For more options, visit https://groups.google.com/d/optout. >>>> >>> >>> >>> -- >>> >> >>> Andrea Leopardi >>> [email protected] >>> >> >>> >>> -- >>> You received this message because you are subscribed to the Google >>> Groups "elixir-lang-core" group. >>> >> To unsubscribe from this group and stop receiving emails from it, send an >>> email to [email protected]. >> >> >>> To view this discussion on the web visit >>> https://groups.google.com/d/msgid/elixir-lang-core/CAM9Rf%2BLY6tyh%3DE6iM%2BA7rmyY8dKP-ddCJpB%2BWZDn0jCuJ7FKaA%40mail.gmail.com >>> <https://groups.google.com/d/msgid/elixir-lang-core/CAM9Rf%2BLY6tyh%3DE6iM%2BA7rmyY8dKP-ddCJpB%2BWZDn0jCuJ7FKaA%40mail.gmail.com?utm_medium=email&utm_source=footer> >>> . >>> For more options, visit https://groups.google.com/d/optout. >>> >> >> -- >> You received this message because you are subscribed to the Google Groups >> "elixir-lang-core" group. >> >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected]. >> >> >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/elixir-lang-core/CAOMhEnyR_50BhVdVugiQqDUxY9jUBNRCR23Bao%3DhwQ9Zmeh4PA%40mail.gmail.com >> <https://groups.google.com/d/msgid/elixir-lang-core/CAOMhEnyR_50BhVdVugiQqDUxY9jUBNRCR23Bao%3DhwQ9Zmeh4PA%40mail.gmail.com?utm_medium=email&utm_source=footer> >> . >> For more options, visit https://groups.google.com/d/optout. >> >> -- > You received this message because you are subscribed to the Google Groups > "elixir-lang-core" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/elixir-lang-core/af052020-b329-49e0-a7b7-f0bf487c123c%40googlegroups.com > <https://groups.google.com/d/msgid/elixir-lang-core/af052020-b329-49e0-a7b7-f0bf487c123c%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "elixir-lang-core" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/CAOMhEnyD_PX0zf0XNeAhaubLMT-hXRGYQj55oj%3Dj2J%2BvNNV20A%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
