- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我发现在 Elixir 中传递消息所需的时间与消息的大小成正比,而我希望它相对恒定。由于数据结构是不可变的,因此运行时应该能够通过引用(在恒定时间内)在进程之间传递大型结构。考虑以下测试。
use Bitwise
defmodule PerfTask do
def pack(s) do
{millis, packed} = :timer.tc(fn -> Enum.to_list(s) end)
IO.puts("packed in #{millis} millis")
Task.async(fn -> packed end)
end
def unpack(t) do
{millis, unpacked} = :timer.tc(fn -> Task.await(t) end)
IO.puts("unpacked in #{millis} millis")
unpacked
end
def go(n) do
IO.puts "n = #{n}"
1..n |> pack |> unpack
end
end
PerfTask.go(1 <<< 20)
n = 1048576
packed in 106481 millis
unpacked in 9916 millis
Task
中取出列表所需时间的 10 倍。 . (请注意,列表是在任务开始之前构建的。任务所要做的就是返回已经构建的列表。)
n = 4194304
packed in 397428 millis
unpacked in 38748 millis
$ iex
Erlang/OTP 18 [erts-7.2] [source] [64-bit] [smp:8:8] [async-threads:10] [kernel-poll:false]
Interactive Elixir (1.2.0) - press Ctrl+C to exit (type h() ENTER for help)
Task
模块特有的,而是将其替换为具有相似结果的普通进程。)
最佳答案
根据这个 answer从@rvirding 你的基本假设是有缺陷的。引用维丁先生的话:
. . . current versions of Erlang basically copy everything except for larger binaries. In older pre-SMP times it was feasible to not copy but pass references. While this resulted in very fast message passing it created other problems in the implementation, primarily it made garbage collection more difficult and complicated implementation. I think that today passing references and having shared data could result in excessive locking and synchronisation which is, of course, not a Good Thing.
关于performance - 为什么 Elixir 消息传递时间与消息大小成正比?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35135788/
我有一个 45Gb 的表,大约有 76M 行和 150 列。 当我运行以下简单查询时: SELECT count(*) FROM my_table WHERE `column_of_interest`
如果数组已满并且其大小增加 1 以插入新元素,则插入 N 个元素的时间可以计算为 1+2+ .. N = N^2/2。 (声明长度为 size+1 的新数组并将元素复制到新数组)。 我无法理解,如果不
我是一名优秀的程序员,十分优秀!