git.iko.soy/distributed-process
on master help sign in
Generalize Erlang benchmark same as CH benchmark
commit2b8333ed73c1122fa396234714a0ff5c2199f6fc authorEdsko de Vries <edsko@well-typed.com> dateMon 24 Sep 2012, 12:04 (14 years ago) parente55bb2d
1 file changed+14−9
distributed-process/benchmarks/erlang/throughput.erl+14−9
distributed-process/benchmarks/erlang/throughput.erl+14−9
@@ -1,15 +1,20 @@
11-module(throughput).
22
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)].
49
510counter() ->
611 counter(0).
712
813counter(N) ->
914 receive
10− nothing ->
11− counter(N + 1);
12− {just, Them} ->
15+ {count, List} ->
16+ counter(N + length(List));
17+ {get, Them} ->
1318 Them ! N,
1419 counter(0)
1520 end.
@@ -20,9 +25,9 @@ replicate(N, What) ->
2025 What(),
2126 replicate(N - 1, What).
2227
23−count(N, Them) ->
24− replicate(N, fun() -> {counter, Them} ! nothing end),
25− {counter, Them} ! {just, self()},
28+count(Packets, Size, Them) ->
29+ replicate(Packets, fun() -> {counter, Them} ! {count, nats(Size)} end),
30+ {counter, Them} ! {get, self()},
2631 receive
2732 N -> io:format("Did ~B pings", [N])
2833 end.
@@ -30,5 +35,5 @@ count(N, Them) ->
3035start_counter() ->
3136 register(counter, spawn(throughput, counter, [])).
3237
33−start_count(N, Them) ->
34− count(N, Them).
38+start_count(Packets, Size, Them) ->
39+ count(Packets, Size, Them).