PageRenderTime 19ms CodeModel.GetById 14ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

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