From 066f3d2c9bf3126f91a4339be1f9862fea25cb77 Mon Sep 17 00:00:00 2001 From: Pieter Hintjens Date: Mon, 25 Feb 2013 14:13:15 +0100 Subject: [PATCH] Fixed overflow in local_thr results calculation --- perf/local_thr.cpp | 36 ++++++++++++------------------------ 1 file changed, 12 insertions(+), 24 deletions(-) diff --git a/perf/local_thr.cpp b/perf/local_thr.cpp index 5881ff73..d379f473 100644 --- a/perf/local_thr.cpp +++ b/perf/local_thr.cpp @@ -26,34 +26,21 @@ int main (int argc, char *argv []) { - const char *bind_to; - int message_count; - size_t message_size; - void *ctx; - void *s; - int rc; - int i; - zmq_msg_t msg; - void *watch; - unsigned long elapsed; - unsigned long throughput; - double megabits; - if (argc != 4) { printf ("usage: local_thr \n"); return 1; } - bind_to = argv [1]; - message_size = atoi (argv [2]); - message_count = atoi (argv [3]); + const char *bind_to = argv [1]; + size_t message_size = atoi (argv [2]); + int message_count = atoi (argv [3]); - ctx = zmq_init (1); + void *ctx = zmq_init (1); if (!ctx) { printf ("error in zmq_init: %s\n", zmq_strerror (errno)); return -1; } - s = zmq_socket (ctx, ZMQ_PULL); + void *s = zmq_socket (ctx, ZMQ_PULL); if (!s) { printf ("error in zmq_socket: %s\n", zmq_strerror (errno)); return -1; @@ -62,12 +49,13 @@ int main (int argc, char *argv []) // Add your socket options here. // For example ZMQ_RATE, ZMQ_RECOVERY_IVL and ZMQ_MCAST_LOOP for PGM. - rc = zmq_bind (s, bind_to); + int rc = zmq_bind (s, bind_to); if (rc != 0) { printf ("error in zmq_bind: %s\n", zmq_strerror (errno)); return -1; } + zmq_msg_t msg; rc = zmq_msg_init (&msg); if (rc != 0) { printf ("error in zmq_msg_init: %s\n", zmq_strerror (errno)); @@ -84,8 +72,9 @@ int main (int argc, char *argv []) return -1; } - watch = zmq_stopwatch_start (); + void *watch = zmq_stopwatch_start (); + int i; for (i = 0; i != message_count - 1; i++) { rc = zmq_recvmsg (s, &msg, 0); if (rc < 0) { @@ -98,7 +87,7 @@ int main (int argc, char *argv []) } } - elapsed = zmq_stopwatch_stop (watch); + unsigned long elapsed = zmq_stopwatch_stop (watch); if (elapsed == 0) elapsed = 1; @@ -108,9 +97,8 @@ int main (int argc, char *argv []) return -1; } - throughput = (unsigned long) - ((double) message_count / (double) elapsed * 1000000); - megabits = (double) (throughput * message_size * 8) / 1000000; + double throughput = ((double) message_count / (double) elapsed) * 1000000; + double megabits = (double) (throughput * message_size * 8) / 1000000; printf ("message size: %d [B]\n", (int) message_size); printf ("message count: %d\n", (int) message_count);