diff options
author | Nikos Mavrogiannopoulos <nmav@redhat.com> | 2019-12-04 13:58:21 +0100 |
---|---|---|
committer | Nikos Mavrogiannopoulos <nmav@gnutls.org> | 2019-12-20 20:52:40 +0100 |
commit | 6f314f1cc42a95831228abf1ff771a21223d5fbd (patch) | |
tree | 957fd100f0e13e800604aada7e69e1038ed04124 /src | |
parent | ec5ecd1c63d0e09792127705b8806a0931350471 (diff) | |
download | gnutls-6f314f1cc42a95831228abf1ff771a21223d5fbd.tar.gz |
gnutls-cli: benchmark-tls-kx can work with sub-ms accuracy
This allows micro and nanoseconds to be reported if necessary,
and it changes reporting of sample variance to standard deviation
giving a possibly better overview as it is in the same units as
the average.
Signed-off-by: Nikos Mavrogiannopoulos <nmav@redhat.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/benchmark-tls.c | 38 | ||||
-rw-r--r-- | src/benchmark.h | 6 |
3 files changed, 33 insertions, 13 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 9e16698916..92762fa88a 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -160,7 +160,7 @@ BENCHMARK_SRCS = benchmark-cipher.c benchmark.c benchmark.h benchmark-tls.c gnutls_cli_SOURCES = cli.c common.h common.c \ socket.c socket.h ocsptool-common.c inline_cmds.h \ $(BENCHMARK_SRCS) -gnutls_cli_LDADD = ../lib/libgnutls.la +gnutls_cli_LDADD = ../lib/libgnutls.la -lm if ENABLE_DANE gnutls_cli_LDADD += ../libdane/libgnutls-dane.la endif diff --git a/src/benchmark-tls.c b/src/benchmark-tls.c index 48ca7e2f0a..a9c4ce02db 100644 --- a/src/benchmark-tls.c +++ b/src/benchmark-tls.c @@ -349,7 +349,7 @@ static void test_ciphersuite(const char *cipher_prio, int size) } static -double calc_avg(unsigned int *diffs, unsigned int diffs_size) +double calc_avg(uint64_t *diffs, unsigned int diffs_size) { double avg = 0; unsigned int i; @@ -363,7 +363,7 @@ double calc_avg(unsigned int *diffs, unsigned int diffs_size) } static -double calc_sstdev(unsigned int *diffs, unsigned int diffs_size, +double calc_svar(uint64_t *diffs, unsigned int diffs_size, double avg) { double sum = 0, d; @@ -381,7 +381,7 @@ double calc_sstdev(unsigned int *diffs, unsigned int diffs_size, } -unsigned int total_diffs[32 * 1024]; +uint64_t total_diffs[32 * 1024]; unsigned int total_diffs_size = 0; static void test_ciphersuite_kx(const char *cipher_prio, unsigned pk) @@ -389,19 +389,18 @@ static void test_ciphersuite_kx(const char *cipher_prio, unsigned pk) /* Server stuff. */ gnutls_anon_server_credentials_t s_anoncred; gnutls_session_t server; - int sret, cret; + int sret, cret, ret; const char *str; char *suite = NULL; - /* Client stuff. */ gnutls_anon_client_credentials_t c_anoncred; gnutls_certificate_credentials_t c_certcred, s_certcred; gnutls_session_t client; - /* Need to enable anonymous KX specifically. */ - int ret; + unsigned i; struct benchmark_st st; struct timespec tr_start, tr_stop; - double avg, sstddev; + double avg, svar; gnutls_priority_t priority_cache; + const char *scale; total_diffs_size = 0; @@ -501,7 +500,7 @@ static void test_ciphersuite_kx(const char *cipher_prio, unsigned pk) gnutls_deinit(client); gnutls_deinit(server); - total_diffs[total_diffs_size++] = timespec_sub_ms(&tr_stop, &tr_start); + total_diffs[total_diffs_size++] = timespec_sub_ns(&tr_stop, &tr_start); if (total_diffs_size > sizeof(total_diffs)/sizeof(total_diffs[0])) abort(); @@ -515,10 +514,25 @@ static void test_ciphersuite_kx(const char *cipher_prio, unsigned pk) gnutls_priority_deinit(priority_cache); avg = calc_avg(total_diffs, total_diffs_size); - sstddev = calc_sstdev(total_diffs, total_diffs_size, avg); - printf("%32s %.2f ms, sample variance: %.2f)\n", - "(avg. handshake time:", avg, sstddev); + if (avg < 1000) { + scale = "ns"; + } else if (avg < 1000000) { + scale = "\u00B5s"; + avg /= 1000; + for (i=0;i<total_diffs_size;i++) + total_diffs[i] /= 1000; + } else { + scale = "ms"; + avg /= 1000*1000; + for (i=0;i<total_diffs_size;i++) + total_diffs[i] /= 1000*1000; + } + + svar = calc_svar(total_diffs, total_diffs_size, avg); + + printf("%32s %.2f %s, standard deviation: %.2f)\n", + "(avg. handshake time:", avg, scale, sqrt(svar)); gnutls_anon_free_client_credentials(c_anoncred); gnutls_anon_free_server_credentials(s_anoncred); diff --git a/src/benchmark.h b/src/benchmark.h index 2152e6edcf..a5e2aff124 100644 --- a/src/benchmark.h +++ b/src/benchmark.h @@ -71,4 +71,10 @@ timespec_sub_ms(struct timespec *a, struct timespec *b) return (a->tv_sec - b->tv_sec) * 1000 + (a->tv_nsec - b->tv_nsec) / (1000 * 1000); } +inline static unsigned long +timespec_sub_ns(struct timespec *a, struct timespec *b) +{ + return (a->tv_sec - b->tv_sec) * 1000000000 + (a->tv_nsec - b->tv_nsec); +} + #endif /* GNUTLS_SRC_BENCHMARK_H */ |