From: Niels Möller Date: Mon, 11 Feb 2002 17:44:30 +0000 (+0100) Subject: (display): New function for X-Git-Tag: nettle_1.6_release_20021003~366 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f6ad3413a9253e32a6d476bf633919d3d368c6b8;p=thirdparty%2Fnettle.git (display): New function for displaying the results, including MB/s figures. Rev: src/nettle/examples/nettle-benchmark.c:1.4 --- diff --git a/examples/nettle-benchmark.c b/examples/nettle-benchmark.c index 41e9ed23..6779657f 100644 --- a/examples/nettle-benchmark.c +++ b/examples/nettle-benchmark.c @@ -45,10 +45,19 @@ #include +#if __GNUC__ +# define UNUSED __attribute__ ((__unused__)) +#else +# define UNUSED +#endif + /* Encrypt 100MB, 1K at a time. */ #define BENCH_BLOCK 1024 #define BENCH_COUNT 10240 +/* Total MB:s, for MB/s figures. */ +#define BENCH_TOTAL 10.0 + static double time_function(void (*f)(void *arg), void *arg) { @@ -138,6 +147,15 @@ init_key(unsigned length, key[i] = i; } +static void +display(const char *name, const char *mode, + double elapsed) +{ + printf("%13s (%s): %.2fs, %.3fMB/s\n", + name, mode, + elapsed, BENCH_TOTAL / elapsed); +} + static void time_cipher(const struct nettle_cipher *cipher) { @@ -156,9 +174,9 @@ time_cipher(const struct nettle_cipher *cipher) init_key(cipher->key_size, key); cipher->set_encrypt_key(ctx, cipher->key_size, key); - - printf("%13s (ECB encrypt): %f\n", cipher->name, - time_function(bench_cipher, &info)); + + display(cipher->name, "ECB encrypt", + time_function(bench_cipher, &info)); } { @@ -167,9 +185,9 @@ time_cipher(const struct nettle_cipher *cipher) init_key(cipher->key_size, key); cipher->set_decrypt_key(ctx, cipher->key_size, key); - - printf("%13s (ECB decrypt): %f\n", cipher->name, - time_function(bench_cipher, &info)); + + display(cipher->name, "ECB decrypt", + time_function(bench_cipher, &info)); } if (cipher->block_size) @@ -185,9 +203,8 @@ time_cipher(const struct nettle_cipher *cipher) cipher->set_encrypt_key(ctx, cipher->key_size, key); - printf("%13s (CBC encrypt): %f\n", cipher->name, - time_function(bench_cbc_encrypt, - &info)); + display(cipher->name, "CBC encrypt", + time_function(bench_cbc_encrypt, &info)); } { @@ -198,9 +215,8 @@ time_cipher(const struct nettle_cipher *cipher) cipher->set_decrypt_key(ctx, cipher->key_size, key); - printf("%13s (CBC decrypt): %f\n", cipher->name, - time_function(bench_cbc_decrypt, - &info)); + display(cipher->name, "CBC decrypt", + time_function(bench_cbc_decrypt, &info)); } } } @@ -209,7 +225,7 @@ time_cipher(const struct nettle_cipher *cipher) #define NCIPHERS 12 int -main(int argc, char **argv) +main(int argc UNUSED, char **argv UNUSED) { unsigned i; const struct nettle_cipher *ciphers[NCIPHERS] =