Skip to content

Instantly share code, notes, and snippets.

@jamwt
Created December 7, 2012 00:14
Show Gist options
  • Save jamwt/4229625 to your computer and use it in GitHub Desktop.
Save jamwt/4229625 to your computer and use it in GitHub Desktop.
#include <czmq.h>
#define NUM_MESSAGES (50000000)
void no_op(void *unused1, void *unused2) {}
void run_send() {
zctx_t *ctx = zctx_new();
void *outsock = zsocket_new(ctx, ZMQ_PUSH);
zsocket_connect(outsock, "tcp://localhost:5005");
fprintf(stderr, "sending in 5\n");
sleep(5);
fprintf(stderr, "starting send!\n");
int i;
struct timeval tv;
gettimeofday(&tv, NULL);
for(i=0; i < NUM_MESSAGES; i++) {
zframe_t *fr = zframe_new_zero_copy("hello", 6, no_op, NULL);
zframe_send(&fr, outsock, 0);
}
fprintf(stderr, "start time was: %us %uus\n",
tv.tv_sec, tv.tv_usec);
}
void run_recv() {
zctx_t *ctx = zctx_new();
void *insock = zsocket_new(ctx, ZMQ_PULL);
zsocket_bind(insock, "tcp://*:5005");
fprintf(stderr, "recv ready!\n");
int i;
for(i=0; i < NUM_MESSAGES; i++) {
zframe_t *fr = zframe_recv(insock);
assert(fr);
zframe_destroy(&fr);
}
struct timeval tv;
gettimeofday(&tv, NULL);
fprintf(stderr, "end time was: %us %uus\n",
tv.tv_sec, tv.tv_usec);
}
int main(int argc, char **argv) {
if (argc != 2) {
fprintf(stderr, "require one argument: 'send' or 'recv'\n");
return 1;
}
if (!strcmp(argv[1], "send"))
run_send();
else if (!strcmp(argv[1], "recv"))
run_recv();
else {
fprintf(stderr, "argument must be either 'send' or 'recv'\n");
return 1;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment