Commit f6ad3413 authored by Niels Möller's avatar Niels Möller
Browse files

(display): New function for

displaying the results, including MB/s figures.

Rev: src/nettle/examples/nettle-benchmark.c:1.4
parent dd026f9c
...@@ -45,10 +45,19 @@ ...@@ -45,10 +45,19 @@
#include <time.h> #include <time.h>
#if __GNUC__
# define UNUSED __attribute__ ((__unused__))
#else
# define UNUSED
#endif
/* Encrypt 100MB, 1K at a time. */ /* Encrypt 100MB, 1K at a time. */
#define BENCH_BLOCK 1024 #define BENCH_BLOCK 1024
#define BENCH_COUNT 10240 #define BENCH_COUNT 10240
/* Total MB:s, for MB/s figures. */
#define BENCH_TOTAL 10.0
static double static double
time_function(void (*f)(void *arg), void *arg) time_function(void (*f)(void *arg), void *arg)
{ {
...@@ -138,6 +147,15 @@ init_key(unsigned length, ...@@ -138,6 +147,15 @@ init_key(unsigned length,
key[i] = i; 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 static void
time_cipher(const struct nettle_cipher *cipher) time_cipher(const struct nettle_cipher *cipher)
{ {
...@@ -157,7 +175,7 @@ time_cipher(const struct nettle_cipher *cipher) ...@@ -157,7 +175,7 @@ time_cipher(const struct nettle_cipher *cipher)
init_key(cipher->key_size, key); init_key(cipher->key_size, key);
cipher->set_encrypt_key(ctx, cipher->key_size, key); cipher->set_encrypt_key(ctx, cipher->key_size, key);
printf("%13s (ECB encrypt): %f\n", cipher->name, display(cipher->name, "ECB encrypt",
time_function(bench_cipher, &info)); time_function(bench_cipher, &info));
} }
...@@ -168,7 +186,7 @@ time_cipher(const struct nettle_cipher *cipher) ...@@ -168,7 +186,7 @@ time_cipher(const struct nettle_cipher *cipher)
init_key(cipher->key_size, key); init_key(cipher->key_size, key);
cipher->set_decrypt_key(ctx, cipher->key_size, key); cipher->set_decrypt_key(ctx, cipher->key_size, key);
printf("%13s (ECB decrypt): %f\n", cipher->name, display(cipher->name, "ECB decrypt",
time_function(bench_cipher, &info)); time_function(bench_cipher, &info));
} }
...@@ -185,9 +203,8 @@ time_cipher(const struct nettle_cipher *cipher) ...@@ -185,9 +203,8 @@ time_cipher(const struct nettle_cipher *cipher)
cipher->set_encrypt_key(ctx, cipher->key_size, key); cipher->set_encrypt_key(ctx, cipher->key_size, key);
printf("%13s (CBC encrypt): %f\n", cipher->name, display(cipher->name, "CBC encrypt",
time_function(bench_cbc_encrypt, time_function(bench_cbc_encrypt, &info));
&info));
} }
{ {
...@@ -198,9 +215,8 @@ time_cipher(const struct nettle_cipher *cipher) ...@@ -198,9 +215,8 @@ time_cipher(const struct nettle_cipher *cipher)
cipher->set_decrypt_key(ctx, cipher->key_size, key); cipher->set_decrypt_key(ctx, cipher->key_size, key);
printf("%13s (CBC decrypt): %f\n", cipher->name, display(cipher->name, "CBC decrypt",
time_function(bench_cbc_decrypt, time_function(bench_cbc_decrypt, &info));
&info));
} }
} }
} }
...@@ -209,7 +225,7 @@ time_cipher(const struct nettle_cipher *cipher) ...@@ -209,7 +225,7 @@ time_cipher(const struct nettle_cipher *cipher)
#define NCIPHERS 12 #define NCIPHERS 12
int int
main(int argc, char **argv) main(int argc UNUSED, char **argv UNUSED)
{ {
unsigned i; unsigned i;
const struct nettle_cipher *ciphers[NCIPHERS] = const struct nettle_cipher *ciphers[NCIPHERS] =
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment