From ec6822a477b89ac77afc90425bf36c4829dbef3d Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 8 Sep 2009 11:30:49 +0200 Subject: win port for c and cpp perf tests --- perf/c/local_lat.c | 3 +-- perf/c/local_thr.c | 24 +++++++----------------- perf/c/remote_lat.c | 19 +++++-------------- perf/c/remote_thr.c | 3 +-- perf/cpp/local_lat.cpp | 3 +-- perf/cpp/local_thr.cpp | 20 ++++---------------- perf/cpp/remote_lat.cpp | 16 +++------------- perf/cpp/remote_thr.cpp | 3 +-- 8 files changed, 23 insertions(+), 68 deletions(-) (limited to 'perf') diff --git a/perf/c/local_lat.c b/perf/c/local_lat.c index 92cfadf..86d4721 100644 --- a/perf/c/local_lat.c +++ b/perf/c/local_lat.c @@ -20,7 +20,6 @@ #include #include #include -#include #include int main (int argc, char *argv []) @@ -66,7 +65,7 @@ int main (int argc, char *argv []) rc = zmq_msg_close (&msg); assert (rc == 0); - sleep (1); + zmq_sleep (1); rc = zmq_close (s); assert (rc == 0); diff --git a/perf/c/local_thr.c b/perf/c/local_thr.c index 71ed21c..83ebee1 100644 --- a/perf/c/local_thr.c +++ b/perf/c/local_thr.c @@ -21,8 +21,6 @@ #include #include #include -#include -#include int main (int argc, char *argv []) { @@ -34,10 +32,9 @@ int main (int argc, char *argv []) int rc; int i; struct zmq_msg_t msg; - struct timeval start; - struct timeval end; - uint64_t elapsed; - uint64_t throughput; + void *watch; + unsigned long elapsed; + unsigned long throughput; double megabits; if (argc != 4) { @@ -64,8 +61,7 @@ int main (int argc, char *argv []) assert (rc == 0); assert (zmq_msg_size (&msg) == message_size); - rc = gettimeofday (&start, NULL); - assert (rc == 0); + watch = zmq_stopwatch_start (); for (i = 0; i != message_count - 1; i++) { rc = zmq_recv (s, &msg, 0); @@ -73,17 +69,11 @@ int main (int argc, char *argv []) assert (zmq_msg_size (&msg) == message_size); } - rc = gettimeofday (&end, NULL); - assert (rc == 0); - - end.tv_sec -= start.tv_sec; - start.tv_sec = 0; - - elapsed = ((uint64_t) end.tv_sec * 1000000 + end.tv_usec) - - ((uint64_t) start.tv_sec * 1000000 + start.tv_usec); + elapsed = zmq_stopwatch_stop (watch); if (elapsed == 0) elapsed = 1; - throughput = (uint64_t) message_count * 1000000 / elapsed; + + throughput = (double) message_count / (double) elapsed * 1000000; megabits = (double) (throughput * message_size * 8) / 1000000; printf ("message size: %d [B]\n", (int) message_size); diff --git a/perf/c/remote_lat.c b/perf/c/remote_lat.c index 6da1c42..23695b4 100644 --- a/perf/c/remote_lat.c +++ b/perf/c/remote_lat.c @@ -21,7 +21,6 @@ #include #include #include -#include int main (int argc, char *argv []) { @@ -33,9 +32,8 @@ int main (int argc, char *argv []) int rc; int i; struct zmq_msg_t msg; - struct timeval start; - struct timeval end; - double elapsed; + void *watch; + unsigned long elapsed; double latency; if (argc != 4) { @@ -56,8 +54,7 @@ int main (int argc, char *argv []) rc = zmq_connect (s, connect_to); assert (rc == 0); - rc = gettimeofday (&start, NULL); - assert (rc == 0); + watch = zmq_stopwatch_start (); rc = zmq_msg_init_size (&msg, message_size); assert (rc == 0); @@ -73,15 +70,9 @@ int main (int argc, char *argv []) rc = zmq_msg_close (&msg); assert (rc == 0); - rc = gettimeofday (&end, NULL); - assert (rc == 0); - - end.tv_sec -= start.tv_sec; - start.tv_sec = 0; + elapsed = zmq_stopwatch_stop (watch); - elapsed = (end.tv_sec * 1000000 + end.tv_usec) - - (start.tv_sec * 1000000 + start.tv_usec); - latency = elapsed / (roundtrip_count * 2); + latency = (double) elapsed / (roundtrip_count * 2); printf ("message size: %d [B]\n", (int) message_size); printf ("roundtrip count: %d\n", (int) roundtrip_count); diff --git a/perf/c/remote_thr.c b/perf/c/remote_thr.c index 9606d00..3069640 100644 --- a/perf/c/remote_thr.c +++ b/perf/c/remote_thr.c @@ -20,7 +20,6 @@ #include #include #include -#include #include int main (int argc, char *argv []) @@ -61,7 +60,7 @@ int main (int argc, char *argv []) assert (rc == 0); } - sleep (10); + zmq_sleep (10); rc = zmq_close (s); assert (rc == 0); diff --git a/perf/cpp/local_lat.cpp b/perf/cpp/local_lat.cpp index 343ca74..d8fee2e 100644 --- a/perf/cpp/local_lat.cpp +++ b/perf/cpp/local_lat.cpp @@ -20,7 +20,6 @@ #include #include #include -#include #include #include @@ -47,7 +46,7 @@ int main (int argc, char *argv []) s.send (msg); } - sleep (1); + zmq_sleep (1); return 0; } diff --git a/perf/cpp/local_thr.cpp b/perf/cpp/local_thr.cpp index 31fcd16..7d40904 100644 --- a/perf/cpp/local_thr.cpp +++ b/perf/cpp/local_thr.cpp @@ -22,8 +22,6 @@ #include #include #include -#include -#include int main (int argc, char *argv []) { @@ -45,27 +43,17 @@ int main (int argc, char *argv []) s.recv (&msg); assert (msg.size () == message_size); - timeval start; - int rc = gettimeofday (&start, NULL); - assert (rc == 0); + void *watch = zmq_stopwatch_start (); for (int i = 1; i != message_count; i++) { s.recv (&msg); assert (msg.size () == message_size); } - timeval end; - rc = gettimeofday (&end, NULL); - assert (rc == 0); + unsigned long elapsed = zmq_stopwatch_stop (watch); - end.tv_sec -= start.tv_sec; - start.tv_sec = 0; - - uint64_t elapsed = ((uint64_t) end.tv_sec * 1000000 + end.tv_usec) - - ((uint64_t) start.tv_sec * 1000000 + start.tv_usec); - if (elapsed == 0) - elapsed = 1; - uint64_t throughput = (uint64_t) message_count * 1000000 / elapsed; + unsigned long throughput = (unsigned long) + ((double) message_count / (double) elapsed * 1000000); double megabits = (double) (throughput * message_size * 8) / 1000000; printf ("message size: %d [B]\n", (int) message_size); diff --git a/perf/cpp/remote_lat.cpp b/perf/cpp/remote_lat.cpp index a88d53d..f1d2a17 100644 --- a/perf/cpp/remote_lat.cpp +++ b/perf/cpp/remote_lat.cpp @@ -22,7 +22,6 @@ #include #include #include -#include int main (int argc, char *argv []) { @@ -40,9 +39,7 @@ int main (int argc, char *argv []) zmq::socket_t s (ctx, ZMQ_REQ); s.connect (connect_to); - timeval start; - int rc = gettimeofday (&start, NULL); - assert (rc == 0); + void *watch = zmq_stopwatch_start (); for (int i = 0; i != roundtrip_count; i++) { zmq::message_t msg (message_size); @@ -51,16 +48,9 @@ int main (int argc, char *argv []) assert (msg.size () == message_size); } - timeval end; - rc = gettimeofday (&end, NULL); - assert (rc == 0); + unsigned long elapsed = zmq_stopwatch_stop (watch); - end.tv_sec -= start.tv_sec; - start.tv_sec = 0; - - double elapsed = (end.tv_sec * 1000000 + end.tv_usec) - - (start.tv_sec * 1000000 + start.tv_usec); - double latency = elapsed / (roundtrip_count * 2); + double latency = (double) elapsed / (roundtrip_count * 2); printf ("message size: %d [B]\n", (int) message_size); printf ("roundtrip count: %d\n", (int) roundtrip_count); diff --git a/perf/cpp/remote_thr.cpp b/perf/cpp/remote_thr.cpp index 5474c6a..a4008df 100644 --- a/perf/cpp/remote_thr.cpp +++ b/perf/cpp/remote_thr.cpp @@ -20,7 +20,6 @@ #include #include #include -#include #include #include @@ -45,7 +44,7 @@ int main (int argc, char *argv []) s.send (msg); } - sleep (10); + zmq_sleep (10); return 0; } -- cgit v1.2.3