/bench/erlang/taskstart.erl

http://github.com/kilim/kilim · Erlang · 39 lines · 20 code · 9 blank · 10 comment · 0 complexity · 792067fdec6f066261bbde9e71b153a0 MD5 · raw file

  1. -module(taskstart).
  2. -export([start/0, startRound/1, launch/1]).
  3. start() ->
  4. Reporter = spawn(taskstart, startRound, [10]),
  5. register(reporter, Reporter).
  6. %---------------------------------------------------------------------
  7. % Reporter
  8. % Spawns a ring in each of n rounds, and waits for the ring
  9. % to signal completion.
  10. %---------------------------------------------------------------------
  11. startRound(0)->
  12. erlang:halt();
  13. startRound(N)->
  14. StartTime = erlang:now(),
  15. spawn(taskstart, launch, [100000]),
  16. receive
  17. EndTime ->
  18. io:format("~p ~p~n", [N, timer:now_diff(EndTime, StartTime)])
  19. end,
  20. startRound(N-1).
  21. %---------------------------------------------------------------------
  22. %Ring
  23. % Each process m spawns process m-1. The last process sends the
  24. % current time to the reporter.
  25. %---------------------------------------------------------------------
  26. launch(0) ->
  27. EndTime = erlang:now(),
  28. whereis(reporter) ! EndTime;
  29. launch(M) ->
  30. spawn(taskstart, launch, [M-1]).