Skip to content
Snippets Groups Projects
Commit 1c16f17c authored by Niels Möller's avatar Niels Möller
Browse files

(BENCH_INTERVAL): Reduced to 0.1 s.

(struct bench_memxor_info): New struct.
(bench_memxor): New function.
(time_memxor): New function.
(main): Use time_memxor. Added optional argument used to limit the
algorithms being benchmarked.

Rev: nettle/examples/nettle-benchmark.c:1.10
parent 47dfe27c
No related branches found
No related tags found
No related merge requests found
......@@ -43,6 +43,7 @@
#include "cast128.h"
#include "cbc.h"
#include "des.h"
#include "memxor.h"
#include "serpent.h"
#include "sha.h"
#include "twofish.h"
......@@ -56,7 +57,7 @@ static double frequency = 0.0;
/* Process BENCH_BLOCK bytes at a time, for BENCH_INTERVAL seconds. */
#define BENCH_BLOCK 10240
#define BENCH_INTERVAL 0.25
#define BENCH_INTERVAL 0.1
/* FIXME: Proper configure test for rdtsc? */
#ifndef WITH_CYCLE_COUNTER
......@@ -132,6 +133,19 @@ time_function(void (*f)(void *arg), void *arg)
#endif /* !HAVE_CLOCK_GETTIME */
}
struct bench_memxor_info
{
uint8_t *dst;
const uint8_t *src;
};
static void
bench_memxor(void *arg)
{
struct bench_memxor_info *info = arg;
memxor (info->dst, info->src, BENCH_BLOCK);
}
struct bench_hash_info
{
void *ctx;
......@@ -248,11 +262,27 @@ xalloc(size_t size)
return p;
}
static void
time_memxor(void)
{
struct bench_memxor_info info;
uint8_t src[BENCH_BLOCK + 1];
uint8_t dst[BENCH_BLOCK + 1];
info.src = src;
info.dst = dst;
display ("xor", "aligned", 1, time_function(bench_memxor, &info));
info.src++;
display ("xor", "unaligned", 1, time_function(bench_memxor, &info));
}
static void
time_hash(const struct nettle_hash *hash)
{
static uint8_t data[BENCH_BLOCK];
struct bench_hash_info info;
info.ctx = xalloc(hash->context_size);
info.update = hash->update;
info.data = data;
......@@ -407,6 +437,7 @@ main(int argc, char **argv)
{
unsigned i;
int c;
const char *alg;
const struct nettle_hash *hashes[] =
{
......@@ -444,21 +475,32 @@ main(int argc, char **argv)
break;
case ':': case '?':
fprintf(stderr, "Usage: nettle-benchmark [-f clock frequency]\n");
fprintf(stderr, "Usage: nettle-benchmark [-f clock frequency] [alg]\n");
return EXIT_FAILURE;
default:
abort();
}
alg = argv[optind];
bench_sha1_compress();
header();
if (!alg || strstr ("memxor", alg))
{
time_memxor();
printf("\n");
}
for (i = 0; hashes[i]; i++)
{
if (!alg || strstr(hashes[i]->name, alg))
time_hash(hashes[i]);
}
for (i = 0; ciphers[i]; i++)
if (!alg || strstr(ciphers[i]->name, alg))
time_cipher(ciphers[i]);
return 0;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment