Skip to content

Instantly share code, notes, and snippets.

@yongboy
Last active December 16, 2015 18:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yongboy/5475628 to your computer and use it in GitHub Desktop.
Save yongboy/5475628 to your computer and use it in GitHub Desktop.
-module(processes).
-export([max/1]).
max(N) ->
Max = erlang:system_info(process_limit),
io:format("Maxmium allowed process 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("Process spawn time=~p (~p) microseconds ~n", [U1, U2]).
wait() ->
receive
die -> void
end.
for(N, N, F) -> [F()];
for(I, N, F) -> [F()|for(I+1, N, F)].
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment