您的位置:首页 > 其它

我的第一个erlang程序

2011-10-11 10:46 183 查看
-module(test81).
-export([start/1]).

start({N,M,Mess})->
statistics(runtime),
statistics(wall_clock),
L=for(1,N,fun()->spawn(fun()->recv() end) end),
for(1,M,fun()->lists:foreach(fun(Pid)->Pid!Mess end,L) end),
{_,Time1}=statistics(runtime),
{_,Time2}=statistics(wall_clock),
U1=Time1*1000,
U2=Time2*1000,
io:format("~w process ~w times message cost time is:~p(~p)microseconds~n",[N,M,U1,U2]).

recv()->
receive
%Mess->io:format("Pid ~p recv message ~p.~n",[self(),Mess]),
Mess->void,
recv()
end.

for(N,N,F)->[F()];
for(I,N,F)->[F()|for(I+1,N,F)].
阅读更多
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: