This is the mail archive of the libc-hacker@sources.redhat.com mailing list for the glibc project.

Note that libc-hacker is a closed list. You may look at the archives of this list, but subscription and posting are not open.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Some improvements to (some) string/test*.c tests/benchmarks


Hi!

This patch adds 2 things:
1) In the IMPL macros in each test one can mark a single test with 2 instead
   of 1.  On measurements where so marked test is slower than the best time,
   an asterix is printed at the end line to visually show where newly tested
   string op is slower than the others.
2) It adds --stringstat=FILE option to the tests, which allows reading
   statistics on the frequency of various alignment/length combinations
   used in real-world usage.  The tests then benchmark the string
   operations with these arguments and also calculate a weighted sum of
   the times.

2005-11-12  Jakub Jelinek  <jakub@redhat.com>

	* string/test-string.h: Include ctype.h, stdbool.h and stdint.h.
	(OPT_STRINGSTAT): Define.
	(struct stringstat): New type.
	(stringstats, test_best_time, overall_best_time, cur_weight,
	weighted_sums): New global variables.
	(CMDLINE_OPTIONS): Add --stringstat=FILE option.
	(CMDLINE_PROCESS): Handle OPT_STRINGSTAT.
	(IMPL_INDEX): Define.
	(read_stringstats, print_stringstats): New functions.
	* string/test-memcmp.c (do_one_test): Compute test_best_time,
	overall_best_time and weighted_sums.
	(do_test): Initialize test_best_time and overall_best_time.
	Print * at the end of line if test_best_time is bigger than
	overall_best_time.
	(test_main): Handle stringstats.
	* string/test-memcpy.c: Likewise.
	* string/test-memset.c: Likewise.
	* string/test-strcmp.c: Likewise.
	* string/test-strcpy.c: Likewise.
	* string/test-strlen.c: Likewise.
	* string/test-strncmp.c: Likewise.
	* string/test-strncpy.c: Likewise.

--- libc/string/test-string.h	7 Mar 2004 09:03:09 -0000	1.4
+++ libc/string/test-string.h	12 Jan 2005 16:01:54 -0000
@@ -1,5 +1,5 @@
 /* Test and measure string and memory functions.
-   Copyright (C) 1999, 2002, 2004 Free Software Foundation, Inc.
+   Copyright (C) 1999, 2002, 2004, 2005 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Written by Jakub Jelinek <jakub@redhat.com>, 1999.
 
@@ -39,6 +39,9 @@ extern impl_t __start_impls[], __stop_im
 
 #undef __USE_STRING_INLINES
 
+#include <ctype.h>
+#include <stdbool.h>
+#include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -58,12 +61,22 @@ extern impl_t __start_impls[], __stop_im
 # define OPT_ITERATIONS 10000
 # define OPT_RANDOM 10001
 # define OPT_SEED 10002
+# define OPT_STRINGSTAT 10003
 
 unsigned char *buf1, *buf2;
 int ret, do_srandom;
 unsigned int seed;
 size_t page_size;
 
+struct stringstat
+{
+  uint32_t len1, len2, align1, align2, count;
+} *stringstats;
+static struct stringstat *read_stringstat (const char *filename);
+
+size_t test_best_time, overall_best_time;
+double cur_weight, *weighted_sums;
+
 hp_timing_t _dl_hp_timing_overhead;
 
 # ifndef ITERATIONS
@@ -81,8 +94,9 @@ size_t iterations = 100000;
 # endif
 
 # define CMDLINE_OPTIONS ITERATIONS_OPTIONS \
-  { "random", no_argument, NULL, OPT_RANDOM },	\
-  { "seed", required_argument, NULL, OPT_SEED },
+  { "random", no_argument, NULL, OPT_RANDOM },				\
+  { "seed", required_argument, NULL, OPT_SEED },			\
+  { "stringstat", required_argument, NULL, OPT_STRINGSTAT },
 # define CMDLINE_PROCESS ITERATIONS_PROCESS \
   case OPT_RANDOM:							\
     {									\
@@ -99,6 +113,10 @@ size_t iterations = 100000;
   case OPT_SEED:							\
     seed = strtoul (optarg, NULL, 0);					\
     do_srandom = 1;							\
+    break;								\
+									\
+  case OPT_STRINGSTAT:							\
+    stringstats = read_stringstats (optarg);				\
     break;
 
 #define CALL(impl, ...)	\
@@ -108,6 +126,8 @@ size_t iterations = 100000;
   for (impl_t *impl = __start_impls; impl < __stop_impls; ++impl)	\
     if (!notall || impl->test)
 
+#define IMPL_INDEX(impl) ((impl) - __start_impls)
+
 #define HP_TIMING_BEST(best_time, start, end)	\
   do									\
     {									\
@@ -149,4 +169,172 @@ test_init (void)
   memset (buf2, 0x5a, page_size);
 }
 
+static struct stringstat *
+read_stringstats (const char *filename)
+{
+  FILE *f = fopen (filename, "r");
+  if (f == NULL)
+    error (EXIT_FAILURE, errno, "could not open stringstat file %s", filename);
+
+  char *line = NULL;
+  size_t linelen = 0;
+  ssize_t len;
+  bool in_section = false;
+  struct stringstat *ret = NULL;
+  size_t retcount = 0, retalloced = 0;
+  struct stringstat cur;
+  while ((len = getline (&line, &len, f)) != -1)
+    {
+      if (len > 0 && line [len - 1] == '\n')
+	line [--len] = '\0';
+      if (!in_section)
+	{
+	  if (len > 8
+	      && memcmp (line, "+++ ", 4) == 0
+	      && memcmp (line + len - 4, " +++", 5) == 0)
+	    {
+	      line [len - 4] = '\0';
+	      FOR_EACH_IMPL (impl, 0)
+		if (strcmp (impl->name, line + 4) == 0)
+		  {
+		    in_section = true;
+		    cur.len1 = -1;
+		    cur.len2 = -1;
+		    break;
+		  }
+	    }
+	}
+      else
+	{
+	  if (len > 8 && memcmp (line, "--- ", 4) == 0)
+	    {
+	      fclose (f);
+	      /* Terminate the array.  */
+	      if (! ret)
+		return NULL;
+	      ret[retcount].len1 = -1;
+	      ret[retcount].len2 = -1;
+	      ret[retcount].align1 = -1;
+	      ret[retcount].align2 = -1;
+	      ret[retcount].count = -1;
+
+	      int count = 0;
+	      FOR_EACH_IMPL (impl, 0)
+		++count;
+
+	      weighted_sums = calloc (count, sizeof (double));
+	      if (weighted_sums == NULL)
+		error (EXIT_FAILURE, errno, "can't allocate weighted sums");
+	      return ret;
+	    }
+
+	  char *p = line;
+	  while (*p && isspace (*p))
+	    p++;
+	  if (*p && *p != '(')
+	    {
+	      if (strncmp (p, "rest", 4) == 0)
+		{
+		  cur.len1 = -1;
+		  p += 4;
+		}
+	      else
+		{
+		  char *end;
+		  cur.len1 = strtoul (p, &end, 0);
+		  if (p == end)
+		    error (EXIT_FAILURE, 0, "invalid stringstat line %s",
+			   line);
+		  p = end;
+		}
+	      if (*p == '/')
+		{
+		  p++;
+		  if (strncmp (p, "rest", 4) == 0)
+		    {
+		      cur.len2 = -1;
+		      p += 4;
+		    }
+		  else
+		    {
+		      char *end;
+		      cur.len2 = strtoul (p, &end, 0);
+		      if (p == end)
+			error (EXIT_FAILURE, 0, "invalid stringstat line %s",
+			       line);
+		      p = end;
+		    }
+		}
+	      else
+		cur.len2 = -1;
+	      while (*p && isspace (*p))
+		p++;
+	      if (*p != ':')
+		error (EXIT_FAILURE, 0, "invalid stringstat line %s", line);
+	      p++;
+	      while (*p && isspace (*p))
+		p++;
+	    }
+	  while (*p == '(')
+	    {
+	      char *end;
+	      cur.align1 = strtoul (p + 1, &end, 0);
+	      if (end == p + 1)
+		error (EXIT_FAILURE, 0, "invalid stringstat line %s", line);
+	      p = end;
+	      if (*p == '/')
+		{
+		  cur.align2 = strtoul (p + 1, &end, 0);
+		  if (end == p + 1)
+		    error (EXIT_FAILURE, 0, "invalid stringstat line %s", line);
+		  p = end;
+		}
+	      else
+		cur.align2 = -1;
+	      if (*p != ')' || p[1] != '=')
+		error (EXIT_FAILURE, 0, "invalid stringstat line %s", line);
+	      cur.count = strtoul (p + 2, &end, 0);
+	      if (end == p + 2)
+		error (EXIT_FAILURE, 0, "invalid stringstat line %s", line);
+	      p = end;
+	      while (*p && isspace (*p))
+		p++;
+	      if (retcount + 1 >= retalloced)
+		{
+		  if (retalloced == 0)
+		    retalloced = 32;
+		  else
+		    retalloced *= 2;
+		  if (retalloced >= UINT32_MAX / sizeof (*ret))
+		    error (EXIT_FAILURE, errno, "string statistics too big");
+		  struct stringstat *new_ret;
+		  new_ret = realloc (ret, retalloced * sizeof (*ret));
+		  if (new_ret == NULL)
+		    error (EXIT_FAILURE, errno,
+			   "can't alloc memory for stringstat");
+		  ret = new_ret;
+		}
+	      ret[retcount++] = cur;
+	    }
+	  if (*p)
+	    error (EXIT_FAILURE, 0, "invalid stringstat line %s", line);
+	}
+    }
+  fclose (f);
+  error (EXIT_FAILURE, 0, "did not find statistics in %s", filename);
+  return NULL;
+}
+
+static void
+print_stringstats (void)
+{
+  if (! HP_TIMING_AVAIL)
+    return;
+
+  printf ("Weighted sums:");
+  FOR_EACH_IMPL (impl, 0)
+    printf ("\t%.f", weighted_sums[IMPL_INDEX (impl)]);
+  putchar ('\n');
+}
+
 #endif
--- libc/string/test-memcmp.c	17 Apr 2003 17:37:24 -0000	1.3
+++ libc/string/test-memcmp.c	12 Jan 2005 16:01:54 -0000
@@ -1,5 +1,5 @@
 /* Test and measure memcmp functions.
-   Copyright (C) 1999, 2002, 2003 Free Software Foundation, Inc.
+   Copyright (C) 1999, 2002, 2003, 2005 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Written by Jakub Jelinek <jakub@redhat.com>, 1999.
 
@@ -67,7 +67,13 @@ do_one_test (impl_t *impl, const char *s
 	  HP_TIMING_BEST (best_time, start, stop);
 	}
 
+      if (impl->test > 1)
+	test_best_time = best_time;
+      if (impl->test && best_time < overall_best_time)
+	overall_best_time = best_time;
       printf ("\t%zd", (size_t) best_time);
+      if (cur_weight)
+	weighted_sums [IMPL_INDEX (impl)] += best_time * cur_weight;
     }
 }
 
@@ -101,11 +107,18 @@ do_test (size_t align1, size_t align2, s
   if (HP_TIMING_AVAIL)
     printf ("Length %4zd, alignment %2zd/%2zd:", len, align1, align2);
 
+  overall_best_time = ~0L;
+  test_best_time = ~0L;
   FOR_EACH_IMPL (impl, 0)
     do_one_test (impl, s1, s2, len, exp_result);
 
   if (HP_TIMING_AVAIL)
-    putchar ('\n');
+    {
+      if (test_best_time < ~0L && test_best_time > overall_best_time)
+	fputs (" *", stdout);
+
+      putchar ('\n');
+    }
 }
 
 static void
@@ -132,7 +145,7 @@ do_random_tests (void)
 	pos = 511 - j - (random () & 7);
       len = random () & 511;
       if (len + j >= 512)
-        len = 511 - j - (random () & 7);
+	len = 511 - j - (random () & 7);
       j = len + align1 + 64;
       if (j > 512) j = 512;
       for (i = 0; i < j; ++i)
@@ -221,6 +234,20 @@ test_main (void)
       do_test (i, 2 * i, 8 << i, -1);
     }
 
+  if (stringstats)
+    {
+      for (struct stringstat *s = stringstats;
+	   s->count != (uint32_t) -1;
+	   s++)
+	{
+	  cur_weight = s->count / 3.0;
+	  do_test (s->align1, s->align2, s->len1, 0);
+	  do_test (s->align1, s->align2, s->len1, 1);
+	  do_test (s->align1, s->align2, s->len1, -1);
+	}
+      print_stringstats ();
+    }
+
   do_random_tests ();
   return ret;
 }
--- libc/string/test-memcpy.c	17 Apr 2003 17:37:24 -0000	1.2
+++ libc/string/test-memcpy.c	12 Jan 2005 16:01:54 -0000
@@ -1,5 +1,5 @@
 /* Test and measure memcpy functions.
-   Copyright (C) 1999, 2002, 2003 Free Software Foundation, Inc.
+   Copyright (C) 1999, 2002, 2003, 2005 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Written by Jakub Jelinek <jakub@redhat.com>, 1999.
 
@@ -84,7 +84,13 @@ do_one_test (impl_t *impl, char *dst, co
 	  HP_TIMING_BEST (best_time, start, stop);
 	}
 
+      if (impl->test > 1)
+	test_best_time = best_time;
+      if (impl->test && best_time < overall_best_time)
+	overall_best_time = best_time;
       printf ("\t%zd", (size_t) best_time);
+      if (cur_weight)
+	weighted_sums [IMPL_INDEX (impl)] += best_time * cur_weight;
     }
 }
 
@@ -111,11 +117,18 @@ do_test (size_t align1, size_t align2, s
   if (HP_TIMING_AVAIL)
     printf ("Length %4zd, alignment %2zd/%2zd:", len, align1, align2);
 
+  overall_best_time = ~0L;
+  test_best_time = ~0L;
   FOR_EACH_IMPL (impl, 0)
     do_one_test (impl, s2, s1, len);
 
   if (HP_TIMING_AVAIL)
-    putchar ('\n');
+    {
+      if (test_best_time < ~0L && test_best_time > overall_best_time)
+	fputs (" *", stdout);
+
+      putchar ('\n');
+    }
 }
 
 static void
@@ -268,6 +281,18 @@ test_main (void)
 
   do_test (0, 0, getpagesize ());
 
+  if (stringstats)
+    {
+      for (struct stringstat *s = stringstats;
+	   s->count != (uint32_t) -1;
+	   s++)
+	{
+	  cur_weight = s->count;
+	  do_test (s->align2, s->align1, s->len1);
+	}
+      print_stringstats ();
+    }
+
   do_random_tests ();
   return ret;
 }
--- libc/string/test-memset.c	17 Apr 2003 17:37:24 -0000	1.2
+++ libc/string/test-memset.c	12 Jan 2005 16:01:54 -0000
@@ -1,5 +1,5 @@
 /* Test and measure memset functions.
-   Copyright (C) 1999, 2002, 2003 Free Software Foundation, Inc.
+   Copyright (C) 1999, 2002, 2003, 2005 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Written by Jakub Jelinek <jakub@redhat.com>, 1999.
 
@@ -72,7 +72,13 @@ do_one_test (impl_t *impl, char *s, int 
 	  HP_TIMING_BEST (best_time, start, stop);
 	}
 
+      if (impl->test > 1)
+	test_best_time = best_time;
+      if (impl->test && best_time < overall_best_time)
+	overall_best_time = best_time;
       printf ("\t%zd", (size_t) best_time);
+      if (cur_weight)
+	weighted_sums [IMPL_INDEX (impl)] += best_time * cur_weight;
     }
 }
 
@@ -86,11 +92,18 @@ do_test (size_t align, int c, size_t len
   if (HP_TIMING_AVAIL)
     printf ("Length %4zd, alignment %2zd, c %2d:", len, align, c);
 
+  overall_best_time = ~0L;
+  test_best_time = ~0L;
   FOR_EACH_IMPL (impl, 0)
     do_one_test (impl, buf1 + align, c, len);
 
   if (HP_TIMING_AVAIL)
-    putchar ('\n');
+    {
+      if (test_best_time < ~0L && test_best_time > overall_best_time)
+	fputs (" *", stdout);
+
+      putchar ('\n');
+    }
 }
 
 static void
@@ -122,7 +135,7 @@ do_random_tests (void)
 	c = random () & 255;
       o = random () & 255;
       if (o == c)
-        o = (c + 1) & 255;
+	o = (c + 1) & 255;
       j = len + align + 128;
       if (j > size)
 	j = size;
@@ -207,6 +220,20 @@ test_main (void)
       do_test (2, c, 25);
     }
 
+  if (stringstats)
+    {
+      for (struct stringstat *s = stringstats;
+	   s->count != (uint32_t) -1;
+	   s++)
+	{
+	  cur_weight = s->count * (2.0 / 3.0);
+	  do_test (s->align1, 0, s->len1);
+	  cur_weight /= 2.0;
+	  do_test (s->align1, 64, s->len1);
+	}
+      print_stringstats ();
+    }
+
   do_random_tests ();
   return ret;
 }
--- libc/string/test-strcmp.c	17 Apr 2003 17:37:24 -0000	1.4
+++ libc/string/test-strcmp.c	12 Jan 2005 16:01:54 -0000
@@ -1,5 +1,5 @@
 /* Test and measure strcmp functions.
-   Copyright (C) 1999, 2002, 2003 Free Software Foundation, Inc.
+   Copyright (C) 1999, 2002, 2003, 2005 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Written by Jakub Jelinek <jakub@redhat.com>, 1999.
 
@@ -81,7 +81,13 @@ do_one_test (impl_t *impl, const char *s
 	  HP_TIMING_BEST (best_time, start, stop);
 	}
 
+      if (impl->test > 1)
+	test_best_time = best_time;
+      if (impl->test && best_time < overall_best_time)
+	overall_best_time = best_time;
       printf ("\t%zd", (size_t) best_time);
+      if (cur_weight)
+	weighted_sums [IMPL_INDEX (impl)] += best_time * cur_weight;
     }
 }
 
@@ -117,11 +123,18 @@ do_test (size_t align1, size_t align2, s
   if (HP_TIMING_AVAIL)
     printf ("Length %4zd, alignment %2zd/%2zd:", len, align1, align2);
 
+  overall_best_time = ~0L;
+  test_best_time = ~0L;
   FOR_EACH_IMPL (impl, 0)
     do_one_test (impl, s1, s2, exp_result);
 
   if (HP_TIMING_AVAIL)
-    putchar ('\n');
+    {
+      if (test_best_time < ~0L && test_best_time > overall_best_time)
+	fputs (" *", stdout);
+
+      putchar ('\n');
+    }
 }
 
 static void
@@ -146,9 +159,9 @@ do_random_tests (void)
 	pos = 510 - j - (random () & 7);
       len1 = random () & 511;
       if (pos >= len1 && (random () & 1))
-        len1 = pos + (random () & 7);
+	len1 = pos + (random () & 7);
       if (len1 + j >= 512)
-        len1 = 511 - j - (random () & 7);
+	len1 = 511 - j - (random () & 7);
       if (pos >= len1)
 	len2 = len1;
       else
@@ -253,6 +266,25 @@ test_main (void)
       do_test (2 * i, i, 8 << i, 254, -1);
     }
 
+  if (stringstats)
+    {
+      for (struct stringstat *s = stringstats;
+	   s->count != (uint32_t) -1;
+	   s++)
+	{
+	  cur_weight = s->count / 4.0;
+	  do_test (s->align1, s->align2, s->len1 < s->len2 ? s->len1 : s->len2,
+		   127, 0);
+	  do_test (s->align1, s->align2, s->len1 < s->len2 ? s->len1 : s->len2,
+		   255, 0);
+	  do_test (s->align1, s->align2, s->len1 < s->len2 ? s->len1 : s->len2,
+		   127, -1);
+	  do_test (s->align1, s->align2, s->len1 < s->len2 ? s->len1 : s->len2,
+		   255, 1);
+	}
+      print_stringstats ();
+    }
+
   do_random_tests ();
   return ret;
 }
--- libc/string/test-strcpy.c	17 Apr 2003 17:37:24 -0000	1.2
+++ libc/string/test-strcpy.c	12 Jan 2005 16:01:54 -0000
@@ -1,5 +1,5 @@
 /* Test and measure strcpy functions.
-   Copyright (C) 1999, 2002, 2003 Free Software Foundation, Inc.
+   Copyright (C) 1999, 2002, 2003, 2005 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Written by Jakub Jelinek <jakub@redhat.com>, 1999.
 
@@ -74,7 +74,13 @@ do_one_test (impl_t *impl, char *dst, co
 	  HP_TIMING_BEST (best_time, start, stop);
 	}
 
+      if (impl->test > 1)
+	test_best_time = best_time;
+      if (impl->test && best_time < overall_best_time)
+	overall_best_time = best_time;
       printf ("\t%zd", (size_t) best_time);
+      if (cur_weight)
+	weighted_sums [IMPL_INDEX (impl)] += best_time * cur_weight;
     }
 }
 
@@ -102,11 +108,18 @@ do_test (size_t align1, size_t align2, s
   if (HP_TIMING_AVAIL)
     printf ("Length %4zd, alignment %2zd/%2zd:", len, align1, align2);
 
+  overall_best_time = ~0L;
+  test_best_time = ~0L;
   FOR_EACH_IMPL (impl, 0)
     do_one_test (impl, s2, s1, len);
 
   if (HP_TIMING_AVAIL)
-    putchar ('\n');
+    {
+      if (test_best_time < ~0L && test_best_time > overall_best_time)
+	fputs (" *", stdout);
+
+      putchar ('\n');
+    }
 }
 
 static void
@@ -220,6 +233,19 @@ test_main (void)
       do_test (i, i, 8 << i, 255);
     }
 
+  if (stringstats)
+    {
+      for (struct stringstat *s = stringstats;
+	   s->count != (uint32_t) -1;
+	   s++)
+	{
+	  cur_weight = s->count / 2.0;
+	  do_test (s->align2, s->align1, s->len1, 127);
+	  do_test (s->align2, s->align1, s->len1, 255);
+	}
+      print_stringstats ();
+    }
+
   do_random_tests ();
   return ret;
 }
--- libc/string/test-strlen.c	17 Apr 2003 17:37:24 -0000	1.2
+++ libc/string/test-strlen.c	12 Jan 2005 16:01:54 -0000
@@ -1,5 +1,5 @@
 /* Test and measure strlen functions.
-   Copyright (C) 1999, 2002, 2003 Free Software Foundation, Inc.
+   Copyright (C) 1999, 2002, 2003, 2005 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Written by Jakub Jelinek <jakub@redhat.com>, 1999.
 
@@ -71,7 +71,13 @@ do_one_test (impl_t *impl, const char *s
 	  HP_TIMING_BEST (best_time, start, stop);
 	}
 
+      if (impl->test > 1)
+	test_best_time = best_time;
+      if (impl->test && best_time < overall_best_time)
+	overall_best_time = best_time;
       printf ("\t%zd", (size_t) best_time);
+      if (cur_weight)
+	weighted_sums [IMPL_INDEX (impl)] += best_time * cur_weight;
     }
 }
 
@@ -91,11 +97,18 @@ do_test (size_t align, size_t len, int m
   if (HP_TIMING_AVAIL)
     printf ("Length %4zd, alignment %2zd:", len, align);
 
+  overall_best_time = ~0L;
+  test_best_time = ~0L;
   FOR_EACH_IMPL (impl, 0)
     do_one_test (impl, buf1 + align, len);
 
   if (HP_TIMING_AVAIL)
-    putchar ('\n');
+    {
+      if (test_best_time < ~0L && test_best_time > overall_best_time)
+	fputs (" *", stdout);
+
+      putchar ('\n');
+    }
 }
 
 static void
@@ -172,6 +185,19 @@ test_main (void)
       do_test (1, 1 << i, 255);
     }
 
+  if (stringstats)
+    {
+      for (struct stringstat *s = stringstats;
+	   s->count != (uint32_t) -1;
+	   s++)
+	{
+	  cur_weight = s->count / 2.0;
+	  do_test (s->align1, s->len1, 127);
+	  do_test (s->align1, s->len1, 255);
+	}
+      print_stringstats ();
+    }
+
   do_random_tests ();
   return ret;
 }
--- libc/string/test-strncmp.c	17 Apr 2003 17:37:24 -0000	1.5
+++ libc/string/test-strncmp.c	12 Jan 2005 16:01:54 -0000
@@ -1,5 +1,5 @@
 /* Test and measure strncmp functions.
-   Copyright (C) 1999, 2002, 2003 Free Software Foundation, Inc.
+   Copyright (C) 1999, 2002, 2003, 2005 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Written by Jakub Jelinek <jakub@redhat.com>, 1999.
 
@@ -81,7 +81,13 @@ do_one_test (impl_t *impl, const char *s
 	  HP_TIMING_BEST (best_time, start, stop);
 	}
 
+      if (impl->test > 1)
+	test_best_time = best_time;
+      if (impl->test && best_time < overall_best_time)
+	overall_best_time = best_time;
       printf ("\t%zd", (size_t) best_time);
+      if (cur_weight)
+	weighted_sums [IMPL_INDEX (impl)] += best_time * cur_weight;
     }
 }
 
@@ -123,11 +129,18 @@ do_test (size_t align1, size_t align2, s
   if (HP_TIMING_AVAIL)
     printf ("Length %4zd/%4zd, alignment %2zd/%2zd:", len, n, align1, align2);
 
+  overall_best_time = ~0L;
+  test_best_time = ~0L;
   FOR_EACH_IMPL (impl, 0)
     do_one_test (impl, s1, s2, n, exp_result);
 
   if (HP_TIMING_AVAIL)
-    putchar ('\n');
+    {
+      if (test_best_time < ~0L && test_best_time > overall_best_time)
+	fputs (" *", stdout);
+
+      putchar ('\n');
+    }
 }
 
 static void
@@ -272,6 +285,29 @@ test_main (void)
       do_test (2 * i, i, 8 << i, 16 << i, 255, 1);
     }
 
+  if (stringstats)
+    {
+      for (struct stringstat *s = stringstats;
+	   s->count != (uint32_t) -1;
+	   s++)
+	{
+	  cur_weight = s->count / 6.0;
+	  do_test (s->align1, s->align2, s->len1 < s->len2 ? s->len1 : s->len2,
+		   s->len1, 127, 0);
+	  do_test (s->align1, s->align2, s->len1 < s->len2 ? s->len1 : s->len2,
+		   s->len1, 127, -1);
+	  do_test (s->align1, s->align2, s->len1 < s->len2 ? s->len1 : s->len2,
+		   s->len1, 127, 1);
+	  do_test (s->align1, s->align2, s->len1 < s->len2 ? s->len1 : s->len2,
+		   s->len1, 255, 0);
+	  do_test (s->align1, s->align2, s->len1 < s->len2 ? s->len1 : s->len2,
+		   s->len1, 255, -1);
+	  do_test (s->align1, s->align2, s->len1 < s->len2 ? s->len1 : s->len2,
+		   s->len1, 255, 1);
+	}
+      print_stringstats ();
+    }
+
   do_random_tests ();
   return ret;
 }
--- libc/string/test-strncpy.c	16 Apr 2003 17:10:51 -0000	1.5
+++ libc/string/test-strncpy.c	12 Jan 2005 16:01:54 -0000
@@ -1,5 +1,5 @@
 /* Test and measure strncpy functions.
-   Copyright (C) 1999, 2002, 2003 Free Software Foundation, Inc.
+   Copyright (C) 1999, 2002, 2003, 2005 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Written by Jakub Jelinek <jakub@redhat.com>, 1999.
 
@@ -106,7 +106,13 @@ do_one_test (impl_t *impl, char *dst, co
 	  HP_TIMING_BEST (best_time, start, stop);
 	}
 
+      if (impl->test > 1)
+	test_best_time = best_time;
+      if (impl->test && best_time < overall_best_time)
+	overall_best_time = best_time;
       printf ("\t%zd", (size_t) best_time);
+      if (cur_weight)
+	weighted_sums [IMPL_INDEX (impl)] += best_time * cur_weight;
     }
 }
 
@@ -136,11 +142,18 @@ do_test (size_t align1, size_t align2, s
   if (HP_TIMING_AVAIL)
     printf ("Length %4zd, n %4zd, alignment %2zd/%2zd:", len, n, align1, align2);
 
+  overall_best_time = ~0L;
+  test_best_time = ~0L;
   FOR_EACH_IMPL (impl, 0)
     do_one_test (impl, s2, s1, len, n);
 
   if (HP_TIMING_AVAIL)
-    putchar ('\n');
+    {
+      if (test_best_time < ~0L && test_best_time > overall_best_time)
+	fputs (" *", stdout);
+
+      putchar ('\n');
+    }
 }
 
 static void
@@ -299,6 +312,19 @@ test_main (void)
       do_test (8 - i, 2 * i, 16 << i, 8 << i, 127);
     }
 
+  if (stringstats)
+    {
+      for (struct stringstat *s = stringstats;
+	   s->count != (uint32_t) -1;
+	   s++)
+	{
+	  cur_weight = s->count / 2.0;
+	  do_test (s->align2, s->align1, s->len2, s->len1, 127);
+	  do_test (s->align2, s->align1, s->len2, s->len1, 255);
+	}
+      print_stringstats ();
+    }
+
   do_random_tests ();
   return ret;
 }

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]