diff options
author | Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> | 2019-12-23 19:04:24 +0000 |
---|---|---|
committer | Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> | 2019-12-23 19:04:24 +0000 |
commit | edbc4cad3cd81612e9c1abeb2c55df4f2d9ef9fa (patch) | |
tree | ad7209b3a6b88f1e032eff517aadeb3c404d6bb3 | |
parent | 7f98b42dfe5a569bace3ed2dbf51fc2e68cc239a (diff) | |
parent | 29730609c59a7172883413cab22e1f4f4e43abd7 (diff) | |
download | gnutls-edbc4cad3cd81612e9c1abeb2c55df4f2d9ef9fa.tar.gz |
Merge branch 'tmp-gnutls-cli' into 'master'
Improvements in gnutls-cli --benchmark-tls-kx
See merge request gnutls/gnutls!1128
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/benchmark-tls.c | 40 | ||||
-rw-r--r-- | src/benchmark.h | 6 |
3 files changed, 34 insertions, 14 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..9df0102cfe 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(); @@ -509,16 +508,31 @@ static void test_ciphersuite_kx(const char *cipher_prio, unsigned pk) } while (benchmark_must_finish == 0); - fprintf(stdout, "%38s ", suite); + fprintf(stdout, "%s\n - ", suite); gnutls_free(suite); stop_benchmark(&st, "transactions", 1); 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(" - avg. handshake time: %.2f %s\n - standard deviation: %.2f %s\n\n", + avg, scale, sqrt(svar), scale); 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 */ |