From 40dba09bd40ada9b216a75ed355c9c1ebd5f9432 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20M=C3=B6ller?= <nisse@lysator.liu.se> Date: Sun, 2 Oct 2005 22:42:23 +0200 Subject: [PATCH] Now display cycles/byte, if the -f option is used to say what the clock frequency is. Rev: src/nettle/examples/nettle-benchmark.c:1.14 --- examples/nettle-benchmark.c | 39 +++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/examples/nettle-benchmark.c b/examples/nettle-benchmark.c index 9b386757..b3def450 100644 --- a/examples/nettle-benchmark.c +++ b/examples/nettle-benchmark.c @@ -36,6 +36,9 @@ #include <time.h> +/* For getopt */ +#include <unistd.h> + #include "aes.h" #include "arcfour.h" #include "blowfish.h" @@ -49,6 +52,7 @@ #include "cbc.h" +static double frequency = 0.0; /* Process BENCH_BLOCK bytes at a time, for BENCH_INTERVAL clocks. */ #define BENCH_BLOCK 10240 @@ -160,13 +164,25 @@ init_key(unsigned length, key[i] = i; } +static void +header(void) +{ + printf("%18s %11s Mbyte/s%s\n", + "Algorithm", "mode", + frequency > 0.0 ? " cycles/byte" : ""); +} + static void display(const char *name, const char *mode, double time) { - printf("%18s (%s): %.3f MB/s\n", + printf("%18s %11s %7.1f", name, mode, BENCH_BLOCK / (time * 1048576.0)); + if (frequency > 0.0) + printf(" %11.1f", time * frequency / BENCH_BLOCK); + + printf("\n"); } static void * @@ -194,7 +210,7 @@ time_hash(const struct nettle_hash *hash) init_data(data); hash->init(info.ctx); - display(hash->name, "Update", + display(hash->name, "update", time_function(bench_hash, &info)); free(info.ctx); @@ -291,6 +307,7 @@ int main(int argc UNUSED, char **argv UNUSED) { unsigned i; + int c; const struct nettle_hash *hashes[] = { @@ -317,6 +334,24 @@ main(int argc UNUSED, char **argv UNUSED) NULL }; + while ( (c = getopt(argc, argv, "f:")) != -1) + switch (c) + { + case 'f': + frequency = atof(optarg); + if (frequency > 0.0) + break; + + case ':': case '?': + fprintf(stderr, "Usage: nettle-benchmark [-f clock frequency]\n"); + return EXIT_FAILURE; + + default: + abort(); + } + + header(); + for (i = 0; hashes[i]; i++) time_hash(hashes[i]); -- GitLab