Skip to content
Browse files

Pulled yrashk's performance tests.

  • Loading branch information...
1 parent 665d8ff commit 322ab82bdcd8c7a94b4976ded5db19a592a337f5 @saleyn saleyn committed Feb 21, 2011
View
18 perf/local_thr.erl → test/perf_local_thr.es
@@ -1,23 +1,31 @@
#! /usr/bin/env escript
%%! -smp enable -pa ebin
+main([]) ->
+ io:format("Usage: ~p BindToAddr MsgSize, MsgCount\n", [escript:script_name()]),
+ erlang:halt(1);
main([BindTo,MessageSizeStr,MessageCountStr]) ->
{MessageSize, _} = string:to_integer(MessageSizeStr),
{MessageCount, _} = string:to_integer(MessageCountStr),
zmq:start_link(),
{ok, Socket} = zmq:socket(sub, [{subscribe, ""},{active, false}]),
ok = zmq:bind(Socket, BindTo),
- {Elapsed, _} = timer:tc(fun () ->
- [ zmq:recv(Socket) || _I <- lists:seq(1,MessageCount) ]
- end,[]),
+ Start = now(),
+ loop(MessageCount, Socket),
+ Elapsed = timer:now_diff(now(), Start),
Throughput = MessageCount / Elapsed * 1000000,
Megabits = Throughput * MessageSize * 8,
io:format("message size: ~p [B]~n"
"message count: ~p~n"
- "mean throughput: ~p [msg/s]~n"
- "mean throughput: ~p [Mb/s]~n",
+ "mean throughput: ~.1f [msg/s]~n"
+ "mean throughput: ~.1f [Mb/s]~n",
[MessageSize, MessageCount, Throughput, Megabits]).
+loop(0, _) ->
+ ok;
+loop(N, S) ->
+ zmq:recv(S),
+ loop(N-1, S).
View
22 perf/local_thr_active.erl → test/perf_local_thr_active.es
@@ -1,23 +1,31 @@
#! /usr/bin/env escript
%%! -smp enable -pa ebin
+main([]) ->
+ io:format("Usage: ~p BindToAddr MsgSize, MsgCount\n", [escript:script_name()]),
+ erlang:halt(1);
main([BindTo,MessageSizeStr,MessageCountStr]) ->
{MessageSize, _} = string:to_integer(MessageSizeStr),
{MessageCount, _} = string:to_integer(MessageCountStr),
zmq:start_link(),
{ok, Socket} = zmq:socket(sub, [{subscribe, ""},{active, true}]),
ok = zmq:bind(Socket, BindTo),
- {Elapsed, _} = timer:tc(fun () ->
- [ receive X -> X end || _I <- lists:seq(1,MessageCount) ]
- end,[]),
-
+ Start = now(),
+ loop(MessageCount, Socket),
+ Elapsed = timer:now_diff(now(), Start),
+
Throughput = MessageCount / Elapsed * 1000000,
Megabits = Throughput * MessageSize * 8,
io:format("message size: ~p [B]~n"
"message count: ~p~n"
- "mean throughput: ~p [msg/s]~n"
- "mean throughput: ~p [Mb/s]~n",
+ "mean throughput: ~.1f [msg/s]~n"
+ "mean throughput: ~.1f [Mb/s]~n",
[MessageSize, MessageCount, Throughput, Megabits]).
-
+
+loop(0, _) ->
+ ok;
+loop(N, S) ->
+ receive X -> X end,
+ loop(N-1, S).
View
12 perf/remote_thr.erl → test/perf_remote_thr.es
@@ -1,12 +1,20 @@
#! /usr/bin/env escript
%%! -smp enable -pa ebin
+main([]) ->
+ io:format("Usage: ~p ConnectToAddr MsgSize, MsgCount\n", [escript:script_name()]),
+ erlang:halt(1);
main([ConnectTo,MessageSizeStr,MessageCountStr]) ->
{MessageSize, _} = string:to_integer(MessageSizeStr),
{MessageCount, _} = string:to_integer(MessageCountStr),
zmq:start_link(),
{ok, Socket} = zmq:socket(pub),
zmq:connect(Socket, ConnectTo),
Msg = list_to_binary(lists:duplicate(MessageSize, 0)),
- [ zmq:send(Socket, Msg) || _I <- lists:seq(1, MessageCount) ].
-
+ loop(MessageCount, Socket, Msg).
+
+loop(0, _, _) ->
+ ok;
+loop(N, S, Msg) ->
+ zmq:send(S, Msg),
+ loop(N-1, S, Msg).

0 comments on commit 322ab82

Please sign in to comment.
Something went wrong with that request. Please try again.