diff options
author | Nick Mathewson <nickm@torproject.org> | 2011-11-11 13:06:17 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2011-11-11 13:06:17 -0500 |
commit | ce51887291decd1654fed6e745fb8f625bf52292 (patch) | |
tree | 1aef77a48d07c5c219d73a7c070a220b627028cc /src/test/bench.c | |
parent | 4c9b6df84da2820a4912b402c54f297126b2305d (diff) | |
download | tor-ce51887291decd1654fed6e745fb8f625bf52292.tar.gz tor-ce51887291decd1654fed6e745fb8f625bf52292.zip |
All-in-one benchmark test for cell crypto
Diffstat (limited to 'src/test/bench.c')
-rw-r--r-- | src/test/bench.c | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/src/test/bench.c b/src/test/bench.c index 634bf93f26..ff2794e7c7 100644 --- a/src/test/bench.c +++ b/src/test/bench.c @@ -14,7 +14,10 @@ const char tor_git_revision[] = ""; #include "orconfig.h" +#define RELAY_PRIVATE + #include "or.h" +#include "relay.h" #if defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_PROCESS_CPUTIME_ID) static uint64_t nanostart; @@ -199,6 +202,59 @@ bench_dmap(void) smartlist_free(sl2); } +static void +bench_cell_ops(void) +{ + const int iters = 1<<16; + int i; + + /* benchmarks for cell ops at relay. */ + or_circuit_t *or_circ = tor_malloc_zero(sizeof(or_circuit_t)); + cell_t *cell = tor_malloc(sizeof(cell_t)); + int outbound; + uint64_t start, end; + + crypto_rand((char*)cell->payload, sizeof(cell->payload)); + + /* Mock-up or_circuit_t */ + or_circ->_base.magic = OR_CIRCUIT_MAGIC; + or_circ->_base.purpose = CIRCUIT_PURPOSE_OR; + + /* Initialize crypto */ + or_circ->p_crypto = crypto_new_cipher_env(); + crypto_cipher_generate_key(or_circ->p_crypto); + crypto_cipher_encrypt_init_cipher(or_circ->p_crypto); + or_circ->n_crypto = crypto_new_cipher_env(); + crypto_cipher_generate_key(or_circ->n_crypto); + crypto_cipher_encrypt_init_cipher(or_circ->n_crypto); + or_circ->p_digest = crypto_new_digest_env(); + or_circ->n_digest = crypto_new_digest_env(); + + reset_perftime(); + + for (outbound = 0; outbound <= 1; ++outbound) { + cell_direction_t d = outbound ? CELL_DIRECTION_OUT : CELL_DIRECTION_IN; + start = perftime(); + for (i = 0; i < iters; ++i) { + char recognized = 0; + crypt_path_t *layer_hint = NULL; + relay_crypt(TO_CIRCUIT(or_circ), cell, d, &layer_hint, &recognized); + } + end = perftime(); + printf("%sbound cells: %.2f ns per cell. (%.2f ns per byte of payload)\n", + outbound?"Out":" In", + NANOCOUNT(start,end,iters), + NANOCOUNT(start,end,iters*CELL_PAYLOAD_SIZE)); + } + + crypto_free_digest_env(or_circ->p_digest); + crypto_free_digest_env(or_circ->n_digest); + crypto_free_cipher_env(or_circ->p_crypto); + crypto_free_cipher_env(or_circ->n_crypto); + tor_free(or_circ); + tor_free(cell); +} + typedef void (*bench_fn)(void); typedef struct benchmark_t { @@ -213,6 +269,7 @@ static struct benchmark_t benchmarks[] = { ENT(dmap), ENT(aes), ENT(cell_aes), + ENT(cell_ops), {NULL,NULL,0} }; @@ -255,6 +312,8 @@ main(int argc, const char **argv) reset_perftime(); + crypto_seed_rng(1); + for (b = benchmarks; b->name; ++b) { if (b->enabled || n_enabled == 0) { printf("===== %s =====\n", b->name); |