Add a benchmark-aes function to test.c. Off by default.

svn:r5485
This commit is contained in:
Nick Mathewson 2005-12-01 04:35:58 +00:00
parent fea19528a1
commit 6443e5ec7f

View File

@ -1548,6 +1548,37 @@ test_rend_fns(void)
crypto_free_pk_env(pk2); 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 int
main(int c, char**v) main(int c, char**v)
{ {
@ -1561,6 +1592,11 @@ main(int c, char**v)
crypto_seed_rng(); crypto_seed_rng();
if (0) {
bench_aes();
return 0;
}
rep_hist_init(); rep_hist_init();
atexit(remove_directory); atexit(remove_directory);