aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/edit_bench.erl
blob: d667862269e1d3558afb95bdd53d7bd21b47fa11 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
-module(edit_bench).

-compile(export_all).

%% Testing the speed of sending (large) cords in messages

cord_bench(Filename, N) ->
    {ok, Cord} = cord:new_from_file(Filename),
    Pid = spawn_link(?MODULE, cord_receiver, []),
    timer:tc(?MODULE, cord_bench_loop, [Cord, Pid, N]).

cord_bench_loop(Cord, Pid, 0) ->
    exit(Pid, kill),
    ok;
cord_bench_loop(Cord, Pid, N) when N > 0 ->
    Pid ! {cord, self(), Cord},
    receive ack -> ok end,
    cord_bench_loop(Cord, Pid, N-1).

cord_receiver() ->
    receive {cord, Who, Cord} -> Who ! ack end,
    cord_receiver().