diff options
author | Werner Koch <wk@gnupg.org> | 2011-02-14 20:31:47 +0100 |
---|---|---|
committer | Werner Koch <wk@gnupg.org> | 2011-02-14 20:31:47 +0100 |
commit | cdedad711a77befcd018e14298ab94a478a822de (patch) | |
tree | 18db341f2e182d4df66bc571244e227089d5a413 /tests/benchmark.c | |
parent | 5ede4ed784148422e3bd2a99ad0e87831f622aa9 (diff) | |
download | libgcrypt-cdedad711a77befcd018e14298ab94a478a822de.tar.gz |
Use a better alignment.
benchmark does now support the option
--alignment 16
to test the non-aligned overhead.
Diffstat (limited to 'tests/benchmark.c')
-rw-r--r-- | tests/benchmark.c | 38 |
1 files changed, 34 insertions, 4 deletions
diff --git a/tests/benchmark.c b/tests/benchmark.c index 76dcd485..465f1b51 100644 --- a/tests/benchmark.c +++ b/tests/benchmark.c @@ -51,6 +51,9 @@ static int cipher_repetitions; /* Number of hash repetitions. */ static int hash_repetitions; +/* Alignment of the buffers. */ +static int buffer_alignment; + /* Whether fips mode was active at startup. */ static int in_fips_mode; @@ -502,6 +505,7 @@ cipher_bench ( const char *algoname ) int keylen, blklen; char key[128]; char *outbuf, *buf; + char *raw_outbuf, *raw_buf; size_t allocated_buflen, buflen; int repetitions; static struct { int mode; const char *name; int blocked; } modes[] = { @@ -537,8 +541,16 @@ cipher_bench ( const char *algoname ) } repetitions *= cipher_repetitions; - buf = gcry_xmalloc (allocated_buflen); - outbuf = gcry_xmalloc (allocated_buflen); + buf = raw_buf = gcry_xmalloc (allocated_buflen+15); + if (buffer_alignment) + while (((size_t)buf & 0x0f)) + buf++; + + outbuf = raw_outbuf = gcry_xmalloc (allocated_buflen+15); + if (buffer_alignment) + while (((size_t)outbuf & 0x0f)) + outbuf++; + if (!header_printed) { @@ -667,8 +679,8 @@ cipher_bench ( const char *algoname ) } putchar ('\n'); - gcry_free (buf); - gcry_free (outbuf); + gcry_free (raw_buf); + gcry_free (raw_outbuf); } @@ -1116,6 +1128,15 @@ main( int argc, char **argv ) argc--; argv++; } } + else if (!strcmp (*argv, "--alignment")) + { + argc--; argv++; + if (argc) + { + buffer_alignment = atoi(*argv); + argc--; argv++; + } + } else if (!strcmp (*argv, "--fips")) { argc--; argv++; @@ -1129,6 +1150,15 @@ main( int argc, char **argv ) } } + switch (buffer_alignment) + { + case 0: + case 16: + break; + default: + die ("option --alignment not used with a value of 0 or 16\n"); + } + gcry_control (GCRYCTL_SET_VERBOSITY, (int)verbose); if (!gcry_check_version (GCRYPT_VERSION)) |