Created
January 23, 2010 04:54
-
-
Save auser/284444 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
-module(p81). | |
-compile(export_all). | |
bench(ProcN, MsgN) -> | |
ProcRing = for(1, ProcN, fun() -> spawn(fun wait/0) end), | |
statistics(runtime), | |
statistics(wall_clock), | |
sendMsgs(ProcRing, ping, ProcN*MsgN), | |
{_, Time1} = statistics(runtime), | |
{_, Time2} = statistics(wall_clock), | |
U1 = Time1 * 1000 / ProcN, | |
U2 = Time2 * 1000 / ProcN, | |
io:format("Process spawn time=~p (~p) microseconds~n", [U1, U2]), | |
%% do I need to kill them afterwards or will the gc do it automatically? | |
lists:foreach(fun(Pid) -> Pid ! die end, ProcRing). | |
wait() -> | |
receive | |
die -> void; | |
ping -> wait() | |
end. | |
% for creating our processes | |
for(N, N, F) -> [F()]; | |
for(I, N, F) -> [F()|for(I+1, N, F)]. | |
sendMsgs(_, _, 0) -> ok; | |
sendMsgs(ProcList, Msg, MsgN) -> | |
lists:foreach(fun(Pid) -> Pid ! Msg end, ProcList), | |
sendMsgs(ProcList, Msg, MsgN-length(ProcList)). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment