これは単純でよく知られたテスト スクリプトです。
-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 はスクリプトを実行する前にコンパイルしませんか? 私はまだ混乱しています。