diff options
author | Nick Mathewson <nickm@torproject.org> | 2005-12-01 04:35:58 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2005-12-01 04:35:58 +0000 |
commit | 6443e5ec7f8315f280b5239350475fc00c592596 (patch) | |
tree | 70bb730401b9f54f8c7f7c08928da7ea19ef3eeb /src | |
parent | fea19528a1dda3a2803533e7bfb4a99de8e45f78 (diff) | |
download | tor-6443e5ec7f8315f280b5239350475fc00c592596.tar.gz tor-6443e5ec7f8315f280b5239350475fc00c592596.zip |
Add a benchmark-aes function to test.c. Off by default.
svn:r5485
Diffstat (limited to 'src')
-rw-r--r-- | src/or/test.c | 36 |
1 files changed, 36 insertions, 0 deletions
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); |