Created
February 14, 2020 11:41
-
-
Save oltarasenko/c13aadb1821ffb9afecca8778ca4df03 to your computer and use it in GitHub Desktop.
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
# Node1: | |
Process.register(self(), :test) | |
x = 100000 | |
list = :lists.seq(1, x) | |
sender = fn -> Enum.each(list, fn x -> send({:test, :'master@127.0.0.1'}, {:msg, x}) end) end | |
sender_pid = | |
spawn( | |
fn -> | |
receive do | |
:start -> sender.() | |
end | |
end) | |
recv = fn _ -> | |
receive do | |
{:msg, x} -> x | |
after 5_000 -> | |
:timeout | |
end | |
end | |
send(sender_pid, :start) | |
# receive | |
:timer.tc(fn -> Enum.each(list, fn _x -> recv.(x) end) end) | |
Gives: | |
:timer.tc(fn -> Enum.each(list, fn _x -> recv.(x) end) end) | |
{216572, :ok} | |
Node2: | |
Process.register(self(), :test) | |
x = 100000 | |
list = :lists.seq(1, x) | |
sender = fn -> Enum.each(list, fn x -> send(:test, {:msg, x}) end) end | |
sender_pid = | |
spawn( | |
fn -> | |
receive do | |
:start -> sender.() | |
end | |
end) | |
recv = fn _ -> | |
receive do | |
{:msg, x} -> x | |
after 5_000 -> | |
:timeout | |
end | |
end | |
send(sender_pid, :start) | |
# receive | |
:timer.tc(fn -> Enum.each(list, fn _x -> recv.(x) end) end) | |
:timer.tc(fn -> Enum.each(list, fn _x -> recv.(x) end) end) | |
{388452, :ok} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
maybe rather, so that sending in part of the measurment: