I’m curious why when I use the Enum.map/2 function, parallelizing it with a Task doesn’t make it run faster, but rather makes it run slower!
When comparing the ‘Unuse Task’ case and the ‘Use Task’ case using the Benchee module, the ‘Unuse Task’ case appeared to be better in terms of execution speed and efficiency, which raised questions.
defmodule TaskTest do
def run() do
list = Enum.to_list(1..100_000)
function = fn i -> i+1 end
Benchee.run(
%{
"Unuse Task" => fn -> Enum.map(list, function) end,
"Use Task" => fn ->
list
|> Enum.map(&(Task.async(fn ->
function.(&1)
end)))
|> Task.await_many()
end
}
)
end
end
TaskTest.run()






















