Commit deb97734 authored by Ian Barber's avatar Ian Barber

Merge pull request #522 from hintjens/master

Fixed overflow in results calculation
parents fb45685a 066f3d2c
......@@ -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 <bind-to> <message-size> <message-count>\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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment