From 6443e5ec7f8315f280b5239350475fc00c592596 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Thu, 1 Dec 2005 04:35:58 +0000 Subject: [PATCH] Add a benchmark-aes function to test.c. Off by default. svn:r5485 --- src/or/test.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/or/test.c b/src/or/test.c index 7d66bdf7ca..850b895ff9 100644 --- a/src/or/test.c +++ b/src/or/test.c @@ -1548,6 +1548,37 @@ test_rend_fns(void) crypto_free_pk_env(pk2); } +static void +bench_aes(void) +{ + int len, i; + char *b1, *b2; + crypto_cipher_env_t *c; + struct timeval start, end; + const int iters = 100000; + uint64_t nsec; + c = crypto_new_cipher_env(); + crypto_cipher_generate_key(c); + crypto_cipher_encrypt_init_cipher(c); + for (len = 1; len <= 8192; len *= 2) { + b1 = tor_malloc_zero(len); + b2 = tor_malloc_zero(len); + tor_gettimeofday(&start); + for (i = 0; i < iters; ++i) { + crypto_cipher_encrypt(c, b1, b2, len); + } + tor_gettimeofday(&end); + tor_free(b1); + tor_free(b2); + nsec = (uint64_t) tv_udiff(&start,&end); + nsec *= 1000; + nsec /= (iters*len); + printf("%d bytes: "U64_FORMAT" nsec per byte\n", len, + U64_PRINTF_ARG(nsec)); + } + crypto_free_cipher_env(c); +} + int main(int c, char**v) { @@ -1561,6 +1592,11 @@ main(int c, char**v) crypto_seed_rng(); + if (0) { + bench_aes(); + return 0; + } + rep_hist_init(); atexit(remove_directory);