当我有这样的代码:
receive do
{:hello, msg} -> msg
end
Run Code Online (Sandbox Code Playgroud)
让我们说N我的邮箱里有邮件.觉得这次特定消息的性能O(1),O(N)或者介于两者之间?
接收执行消息框的线性扫描,然后返回匹配的第一个.有一个例外(自R14A起)
Run Code Online (Sandbox Code Playgroud)OTP-8623 == compiler erts hipe stdlib == Receive statements that can only read out a newly created reference are now specially optimized so that it will execute in constant time regardless of the number of messages in the receive queue for the process. That optimization will benefit calls to gen_server:call(). (See gen:do_call/4 for an example of a receive statement that will be optimized.)
所以在你的情况下它是O(N)操作.
| 归档时间: |
|
| 查看次数: |
214 次 |
| 最近记录: |