Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Elixir 长生不老药综合效率_Elixir - Fatal编程技术网

Elixir 长生不老药综合效率

Elixir 长生不老药综合效率,elixir,Elixir,我有一个大型数据集,我正在使用它执行以下操作: data = %{ city: ["Chiselhurst", "Saskatchewan", "Boston"], day: [1, 2, 3, 4, 5, 6, 7], transportation: ["plane", "train", "automobile"] } defmodule Make do def combos(data) do for city <- data[:city], d

我有一个大型数据集,我正在使用它执行以下操作:

data = %{
  city: ["Chiselhurst", "Saskatchewan", "Boston"],
  day: [1, 2, 3, 4, 5, 6, 7],
  transportation: ["plane", "train", "automobile"]
}

defmodule Make do
  def combos(data) do
    for city <- data[:city],
        day <- data[:day],
        transportation <- data[:transportation] do
          List.flatten([city, day, transportation])
        end
  end

  def filter_map(data) do
    data
    |> Enum.filter_map(fn(x) -> x[:day] > 5 end, &(%{:trip => &1}))
  end

  def combos_filter(data) do
    data
    |> combos
    |> filter_map
  end
end

在实际数据集中的3个列表中,每个列表中大约有多少个元素?添加并发性的最佳位置取决于此。其中2个列表有数千个元素(有时是数百万个元素)。剩下的不到30个。你真的想在末尾列出7个元素的列表(在7个列表中)?我不认为在不同的进程/任务上同时运行这个程序会有任何帮助,如果您想要的最终结果是一个巨大的列表,因为在最后合并每个进程/任务的结果所花费的时间将使从7个本地值创建7个元素的列表相形见绌。那么您认为当前的实现效率低吗?您考虑过吗运行
组合之前进行筛选
?这将减少抛出组合的数据量,并提高效率。在实际数据集中的3个列表中,每个列表中大约有多少个元素?添加并发性的最佳位置取决于此。其中2个列表有数千个元素(有时是数百万个元素)。剩下的不到30个。你真的想在末尾列出7个元素的列表(在7个列表中)?我不认为在不同的进程/任务上同时运行这个程序会有任何帮助,如果您想要的最终结果是一个巨大的列表,因为在最后合并每个进程/任务的结果所花费的时间将使从7个本地值创建7个元素的列表相形见绌。那么您认为当前的实现效率低吗?您考虑过吗运行
组合之前进行筛选
?它将减少抛出组合的数据量,并为您提供一些效率。
day_range = for n <- 1..5_000_000, do: n

data = %{
  city: ["Chiselhurst", "Saskatchewan", "Boston"],
  day: day_range,
  transportation: ["plane", "train", "automobile"]
}


defmodule Make do
  def combos(data) do
    for city <- data[:city],
        day <- data[:day],
        transportation <- data[:transportation] do
          [city, day, transportation]
        end
  end

  def combos_async(data) do
    chiselhurst = Task.async(fn -> partial_combos("Chiselhurst", data) end)
    saskatchewan = Task.async(fn -> partial_combos("Saskatchewan", data) end)
    boston = Task.async( fn -> partial_combos("Boston", data) end)

    Task.await(chiselhurst, 1000000) ++ Task.await(saskatchewan, 1000000) ++ Task.await(boston, 1000000)

  end

  defp partial_combos(city, data) do
    for day <- data[:day],
        transportation <- data[:transportation] do
          [city, day, transportation]
        end
  end

end