[git] GCRYPT - branch, master, updated. post-nuke-of-trailing-ws-13-g61a5212

by Werner Koch cvs at cvs.gnupg.org
Mon Feb 21 10:23:27 CET 2011


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "The GNU crypto library".

The branch, master has been updated
       via  61a521277c6347e99fec8b6575271f705360d802 (commit)
      from  f17d50bbd31b1faa24af1e46c10bba845becf585 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 61a521277c6347e99fec8b6575271f705360d802
Author: Werner Koch <wk at gnupg.org>
Date:   Mon Feb 21 10:00:22 2011 +0100

    Allow --alignment option for md_bench

diff --git a/tests/ChangeLog b/tests/ChangeLog
index 95cb960..281f9fa 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,3 +1,8 @@
+2011-02-21  Werner Koch  <wk at g10code.com>
+
+	* benchmark.c (md_bench): Allow for rthe --alignment option.
+	(main):  Allow alignments between 1 and 16.
+
 2011-02-16  Werner Koch  <wk at g10code.com>
 
 	* benchmark.c (main): Add option --disable-hwf.
diff --git a/tests/benchmark.c b/tests/benchmark.c
index cf78c76..2eca86f 100644
--- a/tests/benchmark.c
+++ b/tests/benchmark.c
@@ -409,8 +409,11 @@ md_bench ( const char *algoname )
 {
   int algo;
   gcry_md_hd_t hd;
-  int i, repcount;
-  char buf[1000];
+  int i, j, repcount;
+  char buf_base[1000+15];
+  size_t bufsize = 1000;
+  char *buf;
+  char *largebuf_base;
   char *largebuf;
   char digest[512/8];
   gcry_error_t err = GPG_ERR_NO_ERROR;
@@ -425,6 +428,8 @@ md_bench ( const char *algoname )
       return;
     }
 
+  buf = buf_base + ((16 - ((size_t)buf_base & 0x0f)) % buffer_alignment);
+
   algo = gcry_md_map_name (algoname);
   if (!algo)
     {
@@ -439,7 +444,7 @@ md_bench ( const char *algoname )
       exit (1);
     }
 
-  for (i=0; i < sizeof buf; i++)
+  for (i=0; i < bufsize; i++)
     buf[i] = i;
 
   printf ("%-12s", gcry_md_algo_name (algo));
@@ -447,7 +452,7 @@ md_bench ( const char *algoname )
   start_timer ();
   for (repcount=0; repcount < hash_repetitions; repcount++)
     for (i=0; i < 1000; i++)
-      gcry_md_write (hd, buf, sizeof buf);
+      gcry_md_write (hd, buf, bufsize);
   gcry_md_final (hd);
   stop_timer ();
   printf (" %s", elapsed_time ());
@@ -457,7 +462,7 @@ md_bench ( const char *algoname )
   start_timer ();
   for (repcount=0; repcount < hash_repetitions; repcount++)
     for (i=0; i < 10000; i++)
-      gcry_md_write (hd, buf, sizeof buf/10);
+      gcry_md_write (hd, buf, bufsize/10);
   gcry_md_final (hd);
   stop_timer ();
   printf (" %s", elapsed_time ());
@@ -467,7 +472,17 @@ md_bench ( const char *algoname )
   start_timer ();
   for (repcount=0; repcount < hash_repetitions; repcount++)
     for (i=0; i < 1000000; i++)
-      gcry_md_write (hd, "", 1);
+      gcry_md_write (hd, buf[0], 1);
+  gcry_md_final (hd);
+  stop_timer ();
+  printf (" %s", elapsed_time ());
+  fflush (stdout);
+
+  start_timer ();
+  for (repcount=0; repcount < hash_repetitions; repcount++)
+    for (i=0; i < 1000; i++)
+      for (j=0; j < bufsize; j++)
+        gcry_md_putc (hd, buf[j]);
   gcry_md_final (hd);
   stop_timer ();
   printf (" %s", elapsed_time ());
@@ -481,9 +496,12 @@ md_bench ( const char *algoname )
   if (gcry_md_get_algo_dlen (algo) > sizeof digest)
     die ("digest buffer too short\n");
 
-  largebuf = malloc (10000);
-  if (!largebuf)
+  largebuf_base = malloc (10000+15);
+  if (!largebuf_base)
     die ("out of core\n");
+  largebuf = (largebuf_base
+              + ((16 - ((size_t)largebuf_base & 0x0f)) % buffer_alignment));
+
   for (i=0; i < 10000; i++)
     largebuf[i] = i;
   start_timer ();
@@ -492,7 +510,7 @@ md_bench ( const char *algoname )
       gcry_md_hash_buffer (algo, digest, largebuf, 10000);
   stop_timer ();
   printf (" %s", elapsed_time ());
-  free (largebuf);
+  free (largebuf_base);
 
   putchar ('\n');
   fflush (stdout);
@@ -544,16 +562,12 @@ cipher_bench ( const char *algoname )
     }
   repetitions *= cipher_repetitions;
 
-  buf = raw_buf = gcry_xmalloc (allocated_buflen+15);
-  if (buffer_alignment)
-    while (((size_t)buf & 0x0f))
-      buf++;
-
+  raw_buf = gcry_xmalloc (allocated_buflen+15);
+  buf = (raw_buf
+         + ((16 - ((size_t)raw_buf & 0x0f)) % buffer_alignment));
   outbuf = raw_outbuf = gcry_xmalloc (allocated_buflen+15);
-  if (buffer_alignment)
-    while (((size_t)outbuf & 0x0f))
-      outbuf++;
-
+  outbuf = (raw_outbuf
+            + ((16 - ((size_t)raw_outbuf & 0x0f)) % buffer_alignment));
 
   if (!header_printed)
     {
@@ -1107,6 +1121,8 @@ main( int argc, char **argv )
   int use_random_daemon = 0;
   int with_progress = 0;
 
+  buffer_alignment = 1;
+
   if (argc)
     { argc--; argv++; }
 
@@ -1201,14 +1217,8 @@ 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");
-    }
+  if (buffer_alignment < 1 || buffer_alignment > 16)
+    die ("value for --alignment must be in the range 1 to 16\n");
 
   gcry_control (GCRYCTL_SET_VERBOSITY, (int)verbose);
 

-----------------------------------------------------------------------

Summary of changes:
 tests/ChangeLog   |    5 ++++
 tests/benchmark.c |   62 ++++++++++++++++++++++++++++++----------------------
 2 files changed, 41 insertions(+), 26 deletions(-)


hooks/post-receive
-- 
The GNU crypto library
http://git.gnupg.org




More information about the Gnupg-commits mailing list