diff options
| author | Garrett D'Amore <garrett@damore.org> | 2018-02-20 19:41:55 -0800 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2018-02-20 19:41:55 -0800 |
| commit | fd871e6ce9de54f81f00918d4c7e3f3f4336b6d3 (patch) | |
| tree | f7758c6430a696f797763d21d5a3d53ea950b561 /perf | |
| parent | 03b9fab6cbf8374aca5f5daa2b5b030bcc4cbb85 (diff) | |
| download | nng-fd871e6ce9de54f81f00918d4c7e3f3f4336b6d3.tar.gz nng-fd871e6ce9de54f81f00918d4c7e3f3f4336b6d3.tar.bz2 nng-fd871e6ce9de54f81f00918d4c7e3f3f4336b6d3.zip | |
Introduce 'porting layer' Public API.
This introduces portable primitives for time, random numbers,
synchronization primitives, and threading. These are somewhat
primitive (least common denominiators), but they can help with writing
portable applications, especially our own demo apps.
Diffstat (limited to 'perf')
| -rw-r--r-- | perf/perf.c | 42 |
1 files changed, 17 insertions, 25 deletions
diff --git a/perf/perf.c b/perf/perf.c index 84a1c66f..593f635e 100644 --- a/perf/perf.c +++ b/perf/perf.c @@ -1,6 +1,6 @@ // -// Copyright 2017 Garrett D'Amore <garrett@damore.org> -// Copyright 2017 Capitar IT Group BV <info@capitar.com> +// Copyright 2018 Staysail Systems, Inc. <info@staysail.tech> +// Copyright 2018 Capitar IT Group BV <info@capitar.com> // // This software is supplied under the terms of the MIT License, a // copy of which should be located in the distribution where this @@ -16,11 +16,7 @@ #include <stdlib.h> #include <string.h> -// We steal access to the clock and thread functions so that we can -// work on Windows too. These functions are *not* part of nng's public -// API, so don't be lazy like this! All nni_ symbols are subject to -// change without notice, and not part of the stable API or ABI. -#include "core/nng_impl.h" +#include "supplemental/util/platform.h" #if defined(NNG_ENABLE_PAIR1) #include "protocol/pair1/pair.h" @@ -224,11 +220,10 @@ do_inproc(void *args) void do_inproc_lat(int argc, char **argv) { - nni_thr thr; + nng_thread *thr; struct inproc_args ia; int rv; - nni_init(); if (argc != 2) { die("Usage: inproc_lat <msg-size> <count>"); } @@ -238,26 +233,24 @@ do_inproc_lat(int argc, char **argv) ia.count = parse_int(argv[1], "count"); ia.func = latency_server; - if ((rv = nni_thr_init(&thr, do_inproc, &ia)) != 0) { + if ((rv = nng_thread_create(&thr, do_inproc, &ia)) != 0) { die("Cannot create thread: %s", nng_strerror(rv)); } - nni_thr_run(&thr); // Sleep a bit. nng_msleep(100); latency_client("inproc://latency_test", ia.msgsize, ia.count); - nni_thr_fini(&thr); + nng_thread_destroy(thr); } void do_inproc_thr(int argc, char **argv) { - nni_thr thr; + nng_thread *thr; struct inproc_args ia; int rv; - nni_init(); if (argc != 2) { die("Usage: inproc_thr <msg-size> <count>"); } @@ -267,12 +260,11 @@ do_inproc_thr(int argc, char **argv) ia.count = parse_int(argv[1], "count"); ia.func = throughput_client; - if ((rv = nni_thr_init(&thr, do_inproc, &ia)) != 0) { + if ((rv = nng_thread_create(&thr, do_inproc, &ia)) != 0) { die("Cannot create thread: %s", nng_strerror(rv)); } - nni_thr_run(&thr); throughput_server("inproc://tput_test", ia.msgsize, ia.count); - nni_thr_fini(&thr); + nng_thread_destroy(thr); } void @@ -280,7 +272,7 @@ latency_client(const char *addr, size_t msgsize, int trips) { nng_socket s; nng_msg * msg; - nni_time start, end; + nng_time start, end; int rv; int i; float total; @@ -301,7 +293,7 @@ latency_client(const char *addr, size_t msgsize, int trips) die("nng_msg_alloc: %s", nng_strerror(rv)); } - start = nni_clock(); + start = nng_clock(); for (i = 0; i < trips; i++) { if ((rv = nng_sendmsg(s, msg, 0)) != 0) { die("nng_sendmsg: %s", nng_strerror(rv)); @@ -311,9 +303,9 @@ latency_client(const char *addr, size_t msgsize, int trips) die("nng_recvmsg: %s", nng_strerror(rv)); } } - end = nni_clock(); + end = nng_clock(); - nni_msg_free(msg); + nng_msg_free(msg); nng_close(s); total = (float) ((end - start)) / 1000; @@ -395,8 +387,8 @@ throughput_server(const char *addr, size_t msgsize, int count) if ((rv = nng_recvmsg(s, &msg, 0)) != 0) { die("nng_recvmsg: %s", nng_strerror(rv)); } - nni_msg_free(msg); - start = nni_clock(); + nng_msg_free(msg); + start = nng_clock(); for (i = 0; i < count; i++) { if ((rv = nng_recvmsg(s, &msg, 0)) != 0) { @@ -406,9 +398,9 @@ throughput_server(const char *addr, size_t msgsize, int count) die("wrong message size: %d != %d", nng_msg_len(msg), msgsize); } - nni_msg_free(msg); + nng_msg_free(msg); } - end = nni_clock(); + end = nng_clock(); nng_close(s); total = (float) ((end - start)) / 1000; msgpersec = (float) (count) / total; |
