Skip to content
Browse files

Fix perf tests

  • Loading branch information...
1 parent ab829c8 commit 920c628c49abcb30bc51caa03e8d0a88b1f2b3cf @evax evax committed Mar 2, 2011
Showing with 31 additions and 11 deletions.
  1. +4 −0 Makefile
  2. +15 −0 perf/ezmq_perf.erl
  3. +9 −8 perf/local_thr.erl
  4. +3 −3 perf/remote_thr.erl
View
4 Makefile
@@ -19,3 +19,7 @@ dependencies: deps/zeromq2/src/.libs/libzmq.a
compile: dependencies
@./rebar compile
+
+perf: compile
+ @cd perf && erlc ezmq_perf.erl
+
View
15 perf/ezmq_perf.erl
@@ -0,0 +1,15 @@
+-module(ezmq_perf).
+-export([recv_loop/2, send_loop/3]).
+
+
+recv_loop(0, _) ->
+ ok;
+recv_loop(N, S) ->
+ ezmq:recv(S),
+ recv_loop(N-1, S).
+
+send_loop(0, _, _) ->
+ ok;
+send_loop(N, S, M) ->
+ ezmq:send(S, M),
+ send_loop(N-1, S, M).
View
17 perf/local_thr.erl
@@ -1,5 +1,6 @@
#! /usr/bin/env escript
-%%! -smp enable -pa ebin
+%%! -smp enable -pa ebin -pa perf
+%-mode(compile).
main([BindTo,MessageSizeStr,MessageCountStr]) ->
{MessageSize, _} = string:to_integer(MessageSizeStr),
@@ -8,17 +9,17 @@ main([BindTo,MessageSizeStr,MessageCountStr]) ->
{ok, Socket} = ezmq:socket(Context, sub),
ok = ezmq:setsockopt(Socket,subscribe, <<>>),
ok = ezmq:bind(Socket, BindTo),
- C = lists:seq(1,MessageCount),
- {Elapsed, _} = timer:tc(fun () ->
- [ ezmq:recv(Socket) || _I <- C ]
- end,[]),
-
+ ezmq:recv(Socket),
+ Start = now(),
+ ezmq_perf:recv_loop(MessageCount-1, Socket),
+ Elapsed = timer:now_diff(now(), Start),
+
Throughput = MessageCount / Elapsed * 1000000,
Megabits = Throughput * MessageSize * 8 / 1000000,
io:format("message size: ~p [B]~n"
"message count: ~p~n"
"mean throughput: ~p [msg/s]~n"
"mean throughput: ~p [Mb/s]~n",
- [MessageSize, MessageCount, Throughput, Megabits]).
-
+ [MessageSize, MessageCount, Throughput, Megabits]).
+
View
6 perf/remote_thr.erl
@@ -1,5 +1,5 @@
#! /usr/bin/env escript
-%%! -smp enable -pa ebin
+%%! -smp enable -pa ebin -pa perf
main([ConnectTo,MessageSizeStr,MessageCountStr]) ->
{MessageSize, _} = string:to_integer(MessageSizeStr),
@@ -8,5 +8,5 @@ main([ConnectTo,MessageSizeStr,MessageCountStr]) ->
{ok, Socket} = ezmq:socket(Context,pub),
ezmq:connect(Socket, ConnectTo),
Msg = list_to_binary(lists:duplicate(MessageSize, 0)),
- C = lists:seq(1, MessageCount),
- [ ezmq:send(Socket, Msg) || _I <- C ].
+ ezmq_perf:send_loop(MessageCount, Socket, Msg).
+

0 comments on commit 920c628

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