summaryrefslogtreecommitdiff
path: root/tests/benchmark.c
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2011-02-14 20:31:47 +0100
committerWerner Koch <wk@gnupg.org>2011-02-14 20:31:47 +0100
commitcdedad711a77befcd018e14298ab94a478a822de (patch)
tree18db341f2e182d4df66bc571244e227089d5a413 /tests/benchmark.c
parent5ede4ed784148422e3bd2a99ad0e87831f622aa9 (diff)
downloadlibgcrypt-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.c38
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))