Created
March 2, 2011 10:29
-
-
Save evax/850750 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/perf/local_thr.erl b/perf/local_thr.erl | |
index 2601e0d..8497fd1 100755 | |
--- a/perf/local_thr.erl | |
+++ b/perf/local_thr.erl | |
@@ -8,11 +8,12 @@ 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:recv_loop(MessageCount-1, Socket), | |
+ Elapsed = timer:now_diff(now(), Start), | |
+ | |
Throughput = MessageCount / Elapsed * 1000000, | |
Megabits = Throughput * MessageSize * 8 / 1000000, | |
@@ -20,5 +21,5 @@ main([BindTo,MessageSizeStr,MessageCountStr]) -> | |
"message count: ~p~n" | |
"mean throughput: ~p [msg/s]~n" | |
"mean throughput: ~p [Mb/s]~n", | |
- [MessageSize, MessageCount, Throughput, Megabits]). | |
- | |
+ [MessageSize, MessageCount, Throughput, Megabits]). | |
+ | |
diff --git a/perf/remote_thr.erl b/perf/remote_thr.erl | |
index ca41d6a..ef1e34b 100755 | |
--- a/perf/remote_thr.erl | |
+++ b/perf/remote_thr.erl | |
@@ -8,5 +8,4 @@ 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:send_loop(MessageCount, Socket, Msg). | |
diff --git a/src/ezmq.erl b/src/ezmq.erl | |
index 58f298b..221ddec 100644 | |
--- a/src/ezmq.erl | |
+++ b/src/ezmq.erl | |
@@ -1,6 +1,7 @@ | |
-module(ezmq). | |
-include_lib("ezmq.hrl"). | |
-export([context/0, context/1, socket/2, bind/2, connect/2, send/2, send/3, brecv/1, brecv/2, recv/1, recv/2, setsockopt/3, getsockopt/2]). | |
+-export([recv_loop/2, send_loop/3]). | |
context() -> | |
context(1). | |
@@ -52,6 +53,20 @@ setsockopt(Socket, Name, Value) -> | |
getsockopt(Socket, Name) -> | |
ezmq_nif:getsockopt(Socket, option_name(Name)). | |
+%% For perf tests | |
+ | |
+recv_loop(0, _) -> | |
+ ok; | |
+recv_loop(N, S) -> | |
+ recv(S), | |
+ recv_loop(N-1, S). | |
+ | |
+send_loop(0, _, _) -> | |
+ ok; | |
+send_loop(N, S, M) -> | |
+ send(S, M), | |
+ send_loop(N-1, S, M). | |
+ | |
%% Private | |
socket_type(pair) -> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment