我的第一个erlang程序

来源:互联网 发布:扫描仪软件 编辑:程序博客网 时间:2024/06/08 19:45
-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)].
0 0