git.iko.soy/distributed-process
on master help sign in
Generalize Erlang benchmark same as CH benchmark
2b8333eEdsko de Vries
distributed-process/benchmarks/erlang/throughput.erl+14−9
@@ -1,15 +1,20 @@
1-module(throughput).
1-module(throughput).
2
2
3−-export([start_counter/0, start_count/2, counter/0, count/2]).
3+-export([start_counter/0, start_count/3, counter/0, count/3, nats/1]).
4+
5+nats(0) ->
6+ [];
7+nats(N) ->
8+ [N | nats(N - 1)].
4
9
5counter() ->
10counter() ->
6 counter(0).
11 counter(0).
7
12
8counter(N) ->
13counter(N) ->
9 receive
14 receive
10− nothing ->
15+ {count, List} ->
11− counter(N + 1);
16+ counter(N + length(List));
12− {just, Them} ->
17+ {get, Them} ->
13 Them ! N,
18 Them ! N,
14 counter(0)
19 counter(0)
15 end.
20 end.
@@ -20,9 +25,9 @@ replicate(N, What) ->
20 What(),
25 What(),
21 replicate(N - 1, What).
26 replicate(N - 1, What).
22
27
23−count(N, Them) ->
28+count(Packets, Size, Them) ->
24− replicate(N, fun() -> {counter, Them} ! nothing end),
29+ replicate(Packets, fun() -> {counter, Them} ! {count, nats(Size)} end),
25− {counter, Them} ! {just, self()},
30+ {counter, Them} ! {get, self()},
26 receive
31 receive
27 N -> io:format("Did ~B pings", [N])
32 N -> io:format("Did ~B pings", [N])
28 end.
33 end.
@@ -30,5 +35,5 @@ count(N, Them) ->
30start_counter() ->
35start_counter() ->
31 register(counter, spawn(throughput, counter, [])).
36 register(counter, spawn(throughput, counter, [])).
32
37
33−start_count(N, Them) ->
38+start_count(Packets, Size, Them) ->
34− count(N, Them).
39+ count(Packets, Size, Them).