这是一个简单而著名的测试脚本:
-module(processes).
-compile(export_all).
max(N)->
Max=erlang:system_info(process_limit),
io:format("the max processes is ~p ~n",[Max]),
statistics(runtime),
statistics(wall_clock),
L=for(1,N,fun()->spawn(fun()->wait() end) end),
{_,Time1}=statistics(runtime),
{_,Time2}=statistics(wall_clock),
lists:foreach(fun(Pid)->Pid!die end,L),
U1=Time1*1000/N,
U2=Time2*1000/N,
io:format("the proecess time is ~p:~p ~n",[U1,U2]).
wait()->
receive
die->void
end.
for(N,N,F)->[F()];
for(I,N,F)->[F()|for(I+1,N,F)].
main([])->
max(100000).
这是erl的输出:
$ erl
Erlang/OTP 17 [erts-6.2] [source] [64-bit] [smp:2:2] [async-threads:10] [kernel-poll:false]
Eshell V6.2 (abort with ^G)
1> c(processes)
1> processes:max(100000).
* 2: syntax error before: processes
1> c(processes).
{ok,processes}
2> processes:max(100000).
the max processes is 262144
the proecess time is 1.1:4.35
ok
这是escript的输出:
$ escript processes.erl
the max processes is 262144
the proecess time is 47.8:83.4
escript和erl之间的确切区别是什么?我是erlang的新手,请帮忙!
编辑:
当 escript 运行梁文件时,它输出与 erl 相同的结果:
$ escript processes.beam
the max processes is 262144
the proecess time is 1.8:3.33
发生什么了?我知道 *.beam 是编译代码,但是 escript 在运行之前不编译脚本?我仍然很困惑。