void *zmq_stopwatch_start () { struct nn_stopwatch *self; self = nn_alloc (sizeof (struct nn_stopwatch), "stopwatch"); alloc_assert (self); nn_stopwatch_init (self); return (void*) self; }
int main (int argc, char *argv []) { const char *connect_to; size_t sz; int rts; char *buf; int nbytes; int s; int rc; int i; int opt; struct nn_stopwatch sw; uint64_t total; double lat; if (argc != 4) { printf ("usage: remote_lat <connect-to> <msg-size> <roundtrips>\n"); return 1; } connect_to = argv [1]; sz = atoi (argv [2]); rts = atoi (argv [3]); s = nn_socket (AF_SP, NN_PAIR); assert (s != -1); opt = 1; rc = nn_setsockopt (s, NN_TCP, NN_TCP_NODELAY, &opt, sizeof (opt)); assert (rc == 0); rc = nn_connect (s, connect_to); assert (rc >= 0); buf = malloc (sz); assert (buf); memset (buf, 111, sz); nn_stopwatch_init (&sw); for (i = 0; i != rts; i++) { nbytes = nn_send (s, buf, sz, 0); assert (nbytes == (int)sz); nbytes = nn_recv (s, buf, sz, 0); assert (nbytes == (int)sz); } total = nn_stopwatch_term (&sw); lat = (double) total / (rts * 2); printf ("message size: %d [B]\n", (int) sz); printf ("roundtrip count: %d\n", (int) rts); printf ("average latency: %.3f [us]\n", (double) lat); free (buf); rc = nn_close (s); assert (rc == 0); return 0; }
int main (int argc, char *argv []) { int rc; int s; int i; char *buf; struct nn_thread thread; struct nn_stopwatch stopwatch; uint64_t elapsed; double latency; if (argc != 3) { printf ("usage: inproc_lat <message-size> <roundtrip-count>\n"); return 1; } message_size = atoi (argv [1]); roundtrip_count = atoi (argv [2]); s = nn_socket (AF_SP, NN_PAIR); assert (s != -1); rc = nn_bind (s, "inproc://inproc_lat"); assert (rc >= 0); buf = malloc (message_size); assert (buf); memset (buf, 111, message_size); /* Wait a bit till the worker thread blocks in nn_recv(). */ nn_thread_init (&thread, worker, NULL); nn_sleep (100); nn_stopwatch_init (&stopwatch); for (i = 0; i != roundtrip_count; i++) { rc = nn_send (s, buf, message_size, 0); assert (rc == (int)message_size); rc = nn_recv (s, buf, message_size, 0); assert (rc == (int)message_size); } elapsed = nn_stopwatch_term (&stopwatch); latency = (double) elapsed / (roundtrip_count * 2); printf ("message size: %d [B]\n", (int) message_size); printf ("roundtrip count: %d\n", (int) roundtrip_count); printf ("average latency: %.3f [us]\n", (double) latency); nn_thread_term (&thread); free (buf); rc = nn_close (s); assert (rc == 0); return 0; }
int main (int argc, char *argv []) { int rc; int s; int i; char *buf; struct nn_thread thread; struct nn_stopwatch stopwatch; uint64_t elapsed; unsigned long throughput; double megabits; if (argc != 3) { printf ("usage: thread_thr <message-size> <message-count>\n"); return 1; } message_size = atoi (argv [1]); message_count = atoi (argv [2]); s = nn_socket (AF_SP, NN_PAIR); assert (s != -1); rc = nn_bind (s, "inproc://inproc_thr"); assert (rc >= 0); buf = malloc (message_size); assert (buf); nn_thread_init (&thread, worker, NULL); /* First message is used to start the stopwatch. */ rc = nn_recv (s, buf, message_size, 0); assert (rc == 0); nn_stopwatch_init (&stopwatch); for (i = 0; i != message_count; i++) { rc = nn_recv (s, buf, message_size, 0); assert (rc == message_size); } elapsed = nn_stopwatch_term (&stopwatch); nn_thread_term (&thread); free (buf); rc = nn_close (s); assert (rc == 0); if (elapsed == 0) elapsed = 1; throughput = (unsigned long) ((double) message_count / (double) elapsed * 1000000); megabits = (double) (throughput * message_size * 8) / 1000000; printf ("message size: %d [B]\n", (int) message_size); printf ("message count: %d\n", (int) message_count); printf ("mean throughput: %d [msg/s]\n", (int) throughput); printf ("mean throughput: %.3f [Mb/s]\n", (double) megabits); return 0; }