Skip to content

Instantly share code, notes, and snippets.

@yjh0502
Created August 20, 2014 11:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save yjh0502/68d6ffce93bcbc425435 to your computer and use it in GitHub Desktop.
Save yjh0502/68d6ffce93bcbc425435 to your computer and use it in GitHub Desktop.
Simple erlang messaging benchmark
-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