This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Pls |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule MyMap do | |
def map_tco(list, function) do | |
Enum.reverse _map_tco([], list, function) | |
end | |
defp _map_tco(acc, [head | tail], function) do | |
_map_tco([function.(head) | acc], tail, function) | |
end | |
defp _map_tco(acc, [], _function) do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
list = Enum.to_list(1..100_000_000) | |
MyMap.map_body(list, fn(i) -> i + 1 end) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
list = Enum.to_list(1..10_000) | |
map_fun = fn(i) -> [i, i * i] end | |
Benchee.run(%{time: 3, parallel: 2}, %{ | |
"flat_map" => fn -> Enum.flat_map(list, map_fun) end, | |
"map.flatten" => fn -> list |> Enum.map(map_fun) |> List.flatten end | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
list = Enum.to_list(1..10_000) | |
map_fun = fn(i) -> [i, i * i] end | |
Benchee.run( | |
%{ | |
formatters: [ | |
&Benchee.Formatters.CSV.output/1, | |
&Benchee.Formatters.Console.output/1 | |
], | |
csv: %{file: "my.csv"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
list = Enum.to_list(1..10_000) | |
map_fun = fn(i) -> [i, i * i] end | |
Benchee.run(%{time: 3}, %{ | |
"flat_map" => fn -> Enum.flat_map(list, map_fun) end, | |
"map.flatten" => fn -> list |> Enum.map(map_fun) |> List.flatten end | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
list = Enum.to_list(1..10_000) | |
map_fun = fn(i) -> [i, i * i] end | |
Benchee.run(%{time: 3, console: %{unit_scaling: :smallest}}, %{ | |
"flat_map" => fn -> Enum.flat_map(list, map_fun) end, | |
"map.flatten" => fn -> list |> Enum.map(map_fun) |> List.flatten end | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DeepMerge.deep_merge(%{a: 1, b: [x: 10, y: 9]}, %{b: [y: 20, z: 30], c: 4}) | |
# => %{a: 1, b: [x: 10, y: 20, z: 30], c: 4} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
list = Enum.to_list(1..10_000) | |
map_fun = fn(i) -> [i, i * i] end | |
Benchee.run(%{ | |
"flat_map" => fn -> Enum.flat_map(list, map_fun) end, | |
"map.flatten" => fn -> list |> Enum.map(map_fun) |> List.flatten end | |
}, | |
formatters: [ | |
&Benchee.Formatters.HTML.output/1, | |
&Benchee.Formatters.Console.output/1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
map_fun = fn(i) -> [i, i * i] end | |
Benchee.run(%{ | |
"flat_map" => fn(input) -> Enum.flat_map(input, map_fun) end, | |
"map.flatten" => fn(input) -> input |> Enum.map(map_fun) |> List.flatten end | |
}, | |
inputs: %{ | |
"Small" => Enum.to_list(1..1000), | |
"Bigger" => Enum.to_list(1..100_000) | |
}) |
OlderNewer