-
-
Save Laymer/7646b6c7fe9832dfdc53a1449a9c3e9e to your computer and use it in GitHub Desktop.
Simple erlang messaging benchmark
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
-module(test). | |
-compile([export_all]). | |
waitdown(0) -> ok; | |
waitdown(Count) -> | |
receive | |
{'DOWN', _, process, _, normal} -> | |
waitdown(Count-1) | |
end. | |
recv(Name, N, Count) -> | |
pg2:start(), | |
lists:foreach(fun(Idx) -> | |
pg2:create({Name, Idx}), | |
spawn_monitor(fun() -> | |
pg2:join({Name, Idx}, self()), | |
(fun Recvmsg(0) -> ok; | |
Recvmsg(Remain) -> | |
receive | |
_ -> Recvmsg(Remain-1) | |
end | |
end)(Count) | |
end) | |
end, lists:seq(1, N)), | |
waitdown(N). | |
send(Name, N, Count) -> | |
pg2:start(), | |
timer:tc(fun() -> | |
lists:foreach(fun(Idx) -> | |
[Target | _] = pg2:get_members({Name, Idx}), | |
spawn_monitor(fun() -> | |
(fun Sendmsg(0) -> ok; | |
Sendmsg(Remain) -> | |
Target ! Remain, | |
Sendmsg(Remain - 1) | |
end)(Count) | |
end) | |
end, lists:seq(1, N)), | |
waitdown(N) | |
end). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment