This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


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] Consolidate *chr benchtests


Hi,

this continue consolidation with *chr benchmarks.

It uses a common bench-chr.h header that i derived from bench-copy.h
it could be factored more in future.

An additional patch to select representative input combinations would
be needed.

OK to commit?


	* benchtests/bench-chr.h: New implementation.
	* benchtests/bench-memchr.c: Include benchtests/bench-chr.h.
	* benchtests/bench-memrchr.c: Likewise.
	* benchtests/bench-rawmemchr.c: Likewise.
	* benchtests/bench-strchr.c: Likewise.
	* benchtests/bench-strchrnul.c: Likewise.
	* benchtests/bench-strlen.c: Likewise.
	* benchtests/bench-strnlen.c: Likewise.
	* benchtests/bench-strrchr.c: Likewise.
---
 benchtests/bench-chr.h       |  105 ++++++++++++++++++++++++
 benchtests/bench-memchr.c    |  113 ++------------------------
 benchtests/bench-memrchr.c   |   28 +++++++
 benchtests/bench-rawmemchr.c |  110 ++-----------------------
 benchtests/bench-strchr.c    |  184 ++----------------------------------------
 benchtests/bench-strchrnul.c |   14 +++-
 benchtests/bench-strlen.c    |  126 ++---------------------------
 benchtests/bench-strnlen.c   |  116 ++------------------------
 benchtests/bench-strrchr.c   |  168 ++------------------------------------
 9 files changed, 179 insertions(+), 785 deletions(-)
 create mode 100644 benchtests/bench-chr.h
 create mode 100644 benchtests/bench-memrchr.c

diff --git a/benchtests/bench-chr.h b/benchtests/bench-chr.h
new file mode 100644
index 0000000..7ec6e12
--- /dev/null
+++ b/benchtests/bench-chr.h
@@ -0,0 +1,105 @@
+/* Measure memcpy, strcpy, stpcpy, ... functions.
+   Copyright (C) 2013 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#define MEMCPY_RESULT(dst, len) dst
+#define MIN_PAGE_SIZE (1<<22)
+#define TEST_MAIN
+#include "bench-string.h"
+
+PROTO
+IMPLS
+
+static void
+do_one_test (impl_t *impl, size_t aligned, size_t len)
+{
+  size_t i, iters = INNER_LOOP_ITERS;
+  timing_t start, stop, cur;
+  static unsigned int r_seed = 42;
+
+  char *srcs[INNER_LOOP_ITERS];
+  for (i = 0; i < iters; ++i)
+    {
+      srcs[i] = ((char *) buf1) + rand_r (&r_seed)%(MIN_PAGE_SIZE/2);
+      if (aligned) /* Align pointers. */
+        {
+          srcs[i] = srcs[i] - ((uintptr_t)srcs[i])%64;
+        }
+    }
+
+  TIMING_NOW (start);
+  for (i = 0; i < iters; ++i)
+    {
+      srcs[i][len] = 0;
+      CALL2 (impl, srcs[i], len);
+      srcs[i][len] = 1;
+    }
+  TIMING_NOW (stop);
+
+  TIMING_DIFF (cur, start, stop);
+
+  TIMING_PRINT_MEAN ((double) cur, (double) iters);
+}
+
+static void
+do_test (size_t aligned, size_t len)
+{
+  printf ("Length %4zd, aligned %c:", len, aligned ? 'y' : 'n' );
+
+  FOR_EACH_IMPL (impl, 0)
+    do_one_test (impl, aligned, len);
+
+  putchar ('\n');
+}
+
+int
+test_main (void)
+{
+  size_t i;
+
+  test_init ();
+
+  memset (buf1, 1, MIN_PAGE_SIZE);
+
+  printf ("%23s", "");
+  FOR_EACH_IMPL (impl, 0)
+    printf ("\t%10s", impl->name);
+  putchar ('\n');
+
+  for (i = 0; i < 18; ++i)
+    {
+      do_test (0, 1 << i);
+      do_test (1, 1 << i);
+    }
+
+  for (i = 0; i < 32; ++i)
+    {
+      do_test (0, i);
+      do_test (1, i);
+    }
+
+  for (i = 3; i < 32; ++i)
+    {
+      do_test (0, 16 * i);
+      do_test (1, 16 * i);
+    }
+
+
+  return ret;
+}
+
+#include "../test-skeleton.c"
diff --git a/benchtests/bench-memchr.c b/benchtests/bench-memchr.c
index db099ad..d429a10 100644
--- a/benchtests/bench-memchr.c
+++ b/benchtests/bench-memchr.c
@@ -16,116 +16,13 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#define TEST_MAIN
-#define TEST_NAME "memchr"
-#include "bench-string.h"
 
-typedef char *(*proto_t) (const char *, int, size_t);
-char *simple_memchr (const char *, int, size_t);
+# define TEST_NAME "memchr"
 
-IMPL (simple_memchr, 0)
-IMPL (memchr, 1)
+#define PROTO typedef char *(*proto_t) (const char *, int, size_t);
+#define IMPLS IMPL (memchr, 1)
 
-char *
-simple_memchr (const char *s, int c, size_t n)
-{
-  while (n--)
-    if (*s++ == (char) c)
-      return (char *) s - 1;
-  return NULL;
-}
 
-static void
-do_one_test (impl_t *impl, const char *s, int c, size_t n, char *exp_res)
-{
-  char *res = CALL (impl, s, c, n);
-  size_t i, iters = INNER_LOOP_ITERS;
-  timing_t start, stop, cur;
+#define CALL2(impl, src, len) CALL (impl, src, 2, len)
 
-  if (res != exp_res)
-    {
-      error (0, 0, "Wrong result in function %s %p %p", impl->name,
-	     res, exp_res);
-      ret = 1;
-      return;
-    }
-
-  TIMING_NOW (start);
-  for (i = 0; i < iters; ++i)
-    {
-      CALL (impl, s, c, n);
-    }
-  TIMING_NOW (stop);
-
-  TIMING_DIFF (cur, start, stop);
-
-  TIMING_PRINT_MEAN ((double) cur, (double) iters);
-}
-
-static void
-do_test (size_t align, size_t pos, size_t len, int seek_char)
-{
-  size_t i;
-  char *result;
-
-  align &= 7;
-  if (align + len >= page_size)
-    return;
-
-  for (i = 0; i < len; ++i)
-    {
-      buf1[align + i] = 1 + 23 * i % 127;
-      if (buf1[align + i] == seek_char)
-        buf1[align + i] = seek_char + 1;
-    }
-  buf1[align + len] = 0;
-
-  if (pos < len)
-    {
-      buf1[align + pos] = seek_char;
-      buf1[align + len] = -seek_char;
-      result = (char *) (buf1 + align + pos);
-    }
-  else
-    {
-      result = NULL;
-      buf1[align + len] = seek_char;
-    }
-
-  printf ("Length %4zd, alignment %2zd:", pos, align);
-
-  FOR_EACH_IMPL (impl, 0)
-    do_one_test (impl, (char *) (buf1 + align), seek_char, len, result);
-
-  putchar ('\n');
-}
-
-int
-test_main (void)
-{
-  size_t i;
-
-  test_init ();
-
-  printf ("%20s", "");
-  FOR_EACH_IMPL (impl, 0)
-    printf ("\t%s", impl->name);
-  putchar ('\n');
-
-  for (i = 1; i < 8; ++i)
-    {
-      do_test (0, 16 << i, 2048, 23);
-      do_test (i, 64, 256, 23);
-      do_test (0, 16 << i, 2048, 0);
-      do_test (i, 64, 256, 0);
-    }
-  for (i = 1; i < 32; ++i)
-    {
-      do_test (0, i, i + 1, 23);
-      do_test (0, i, i + 1, 0);
-    }
-
-  return ret;
-}
-
-#include "../test-skeleton.c"
+#include "bench-chr.h"
diff --git a/benchtests/bench-memrchr.c b/benchtests/bench-memrchr.c
new file mode 100644
index 0000000..d429a10
--- /dev/null
+++ b/benchtests/bench-memrchr.c
@@ -0,0 +1,28 @@
+/* Measure memchr functions.
+   Copyright (C) 2013 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+
+# define TEST_NAME "memchr"
+
+#define PROTO typedef char *(*proto_t) (const char *, int, size_t);
+#define IMPLS IMPL (memchr, 1)
+
+
+#define CALL2(impl, src, len) CALL (impl, src, 2, len)
+
+#include "bench-chr.h"
diff --git a/benchtests/bench-rawmemchr.c b/benchtests/bench-rawmemchr.c
index df6a310..c0057ad 100644
--- a/benchtests/bench-rawmemchr.c
+++ b/benchtests/bench-rawmemchr.c
@@ -1,4 +1,4 @@
-/* Measure memchr functions.
+/* Measure rawmemchr functions.
    Copyright (C) 2013 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
@@ -16,111 +16,13 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#include <assert.h>
 
-#define TEST_MAIN
-#define TEST_NAME "rawmemchr"
-#include "bench-string.h"
+# define TEST_NAME "rawmemchr"
 
-typedef char *(*proto_t) (const char *, int);
-char *simple_rawmemchr (const char *, int);
+#define PROTO typedef char *(*proto_t) (const char *, int);
+#define IMPLS IMPL (rawmemchr, 1)
 
-IMPL (simple_rawmemchr, 0)
-IMPL (rawmemchr, 1)
 
-char *
-simple_rawmemchr (const char *s, int c)
-{
-  while (1)
-    if (*s++ == (char) c)
-      return (char *) s - 1;
-  return NULL;
-}
+#define CALL2(impl, src, len) CALL (impl, src, 0)
 
-static void
-do_one_test (impl_t *impl, const char *s, int c, char *exp_res)
-{
-  size_t i, iters = INNER_LOOP_ITERS;
-  timing_t start, stop, cur;
-  char *res = CALL (impl, s, c);
-  if (res != exp_res)
-    {
-      error (0, 0, "Wrong result in function %s %p %p", impl->name,
-	     res, exp_res);
-      ret = 1;
-      return;
-    }
-
-  TIMING_NOW (start);
-  for (i = 0; i < iters; ++i)
-    {
-      CALL (impl, s, c);
-    }
-  TIMING_NOW (stop);
-
-  TIMING_DIFF (cur, start, stop);
-
-  TIMING_PRINT_MEAN ((double) cur, (double) iters);
-}
-
-static void
-do_test (size_t align, size_t pos, size_t len, int seek_char)
-{
-  size_t i;
-  char *result;
-
-  align &= 7;
-  if (align + len >= page_size)
-    return;
-
-  for (i = 0; i < len; ++i)
-    {
-      buf1[align + i] = 1 + 23 * i % 127;
-      if (buf1[align + i] == seek_char)
-	buf1[align + i] = seek_char + 1;
-    }
-  buf1[align + len] = 0;
-
-  assert (pos < len);
-
-  buf1[align + pos] = seek_char;
-  buf1[align + len] = -seek_char;
-  result = (char *) (buf1 + align + pos);
-
-  printf ("Length %4zd, alignment %2zd:", pos, align);
-
-  FOR_EACH_IMPL (impl, 0)
-    do_one_test (impl, (char *) (buf1 + align), seek_char, result);
-
-  putchar ('\n');
-}
-
-int
-test_main (void)
-{
-  size_t i;
-
-  test_init ();
-
-  printf ("%20s", "");
-  FOR_EACH_IMPL (impl, 0)
-    printf ("\t%s", impl->name);
-  putchar ('\n');
-
-  for (i = 1; i < 7; ++i)
-    {
-      do_test (0, 16 << i, 2048, 23);
-      do_test (i, 64, 256, 23);
-      do_test (0, 16 << i, 2048, 0);
-      do_test (i, 64, 256, 0);
-    }
-  for (i = 1; i < 32; ++i)
-    {
-      do_test (0, i, i + 1, 23);
-      do_test (0, i, i + 1, 0);
-    }
-
-  return ret;
-}
-
-#include "../test-skeleton.c"
+#include "bench-chr.h"
diff --git a/benchtests/bench-strchr.c b/benchtests/bench-strchr.c
index d432ba5..8cd2912 100644
--- a/benchtests/bench-strchr.c
+++ b/benchtests/bench-strchr.c
@@ -1,4 +1,4 @@
-/* Measure STRCHR functions.
+/* Measure strchr functions.
    Copyright (C) 2013 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
@@ -16,185 +16,13 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#define TEST_MAIN
-#ifndef WIDE
-# ifdef USE_FOR_STRCHRNUL
-#  define TEST_NAME "strchrnul"
-# else
-#  define TEST_NAME "strchr"
-# endif
-#else
-# define TEST_NAME "wcschr"
-#endif
-#include "bench-string.h"
 
-#ifndef WIDE
-# ifdef USE_FOR_STRCHRNUL
-#  define STRCHR strchrnul
-#  define stupid_STRCHR stupid_STRCHRNUL
-#  define simple_STRCHR simple_STRCHRNUL
-# else
-#  define STRCHR strchr
-# endif
-# define STRLEN strlen
-# define CHAR char
-# define BIG_CHAR CHAR_MAX
-# define MIDDLE_CHAR 127
-# define SMALL_CHAR 23
-# define UCHAR unsigned char
-#else
-# include <wchar.h>
-# define STRCHR wcschr
-# define STRLEN wcslen
-# define CHAR wchar_t
-# define BIG_CHAR WCHAR_MAX
-# define MIDDLE_CHAR 1121
-# define SMALL_CHAR 851
-# define UCHAR wchar_t
-#endif
+# define TEST_NAME "strchr"
 
-#ifdef USE_FOR_STRCHRNUL
-# define NULLRET(endptr) endptr
-#else
-# define NULLRET(endptr) NULL
-#endif
+#define PROTO typedef char *(*proto_t) (const char *, int);
+#define IMPLS IMPL (strchr, 1)
 
 
-typedef CHAR *(*proto_t) (const CHAR *, int);
+#define CALL2(impl, src, len) CALL (impl, src, 2)
 
-CHAR *
-simple_STRCHR (const CHAR *s, int c)
-{
-  for (; *s != (CHAR) c; ++s)
-    if (*s == '\0')
-      return NULLRET ((CHAR *) s);
-  return (CHAR *) s;
-}
-
-CHAR *
-stupid_STRCHR (const CHAR *s, int c)
-{
-  size_t n = STRLEN (s) + 1;
-
-  while (n--)
-    if (*s++ == (CHAR) c)
-      return (CHAR *) s - 1;
-  return NULLRET ((CHAR *) s - 1);
-}
-
-IMPL (stupid_STRCHR, 0)
-IMPL (simple_STRCHR, 0)
-IMPL (STRCHR, 1)
-
-static void
-do_one_test (impl_t *impl, const CHAR *s, int c, const CHAR *exp_res)
-{
-  size_t i, iters = INNER_LOOP_ITERS;
-  timing_t start, stop, cur;
-
-  TIMING_NOW (start);
-  for (i = 0; i < iters; ++i)
-    {
-      CALL (impl, s, c);
-    }
-  TIMING_NOW (stop);
-
-  TIMING_DIFF (cur, start, stop);
-
-  TIMING_PRINT_MEAN ((double) cur, (double) iters);
-}
-
-static void
-do_test (size_t align, size_t pos, size_t len, int seek_char, int max_char)
-/* For wcschr: align here means align not in bytes,
-   but in wchar_ts, in bytes it will equal to align * (sizeof (wchar_t))
-   len for wcschr here isn't in bytes but it's number of wchar_t symbols.  */
-{
-  size_t i;
-  CHAR *result;
-  CHAR *buf = (CHAR *) buf1;
-  align &= 15;
-  if ((align + len) * sizeof (CHAR) >= page_size)
-    return;
-
-  for (i = 0; i < len; ++i)
-    {
-      buf[align + i] = 32 + 23 * i % max_char;
-      if (buf[align + i] == seek_char)
-	buf[align + i] = seek_char + 1;
-      else if (buf[align + i] == 0)
-	buf[align + i] = 1;
-    }
-  buf[align + len] = 0;
-
-  if (pos < len)
-    {
-      buf[align + pos] = seek_char;
-      result = buf + align + pos;
-    }
-  else if (seek_char == 0)
-    result = buf + align + len;
-  else
-    result = NULLRET (buf + align + len);
-
-  printf ("Length %4zd, alignment in bytes %2zd:",
-	  pos, align * sizeof (CHAR));
-
-  FOR_EACH_IMPL (impl, 0)
-    do_one_test (impl, buf + align, seek_char, result);
-
-  putchar ('\n');
-}
-
-int
-test_main (void)
-{
-  size_t i;
-
-  test_init ();
-
-  printf ("%20s", "");
-  FOR_EACH_IMPL (impl, 0)
-    printf ("\t%s", impl->name);
-  putchar ('\n');
-
-  for (i = 1; i < 8; ++i)
-    {
-      do_test (0, 16 << i, 2048, SMALL_CHAR, MIDDLE_CHAR);
-      do_test (i, 16 << i, 2048, SMALL_CHAR, MIDDLE_CHAR);
-    }
-
-  for (i = 1; i < 8; ++i)
-    {
-      do_test (i, 64, 256, SMALL_CHAR, MIDDLE_CHAR);
-      do_test (i, 64, 256, SMALL_CHAR, BIG_CHAR);
-    }
-
-  for (i = 0; i < 32; ++i)
-    {
-      do_test (0, i, i + 1, SMALL_CHAR, MIDDLE_CHAR);
-      do_test (0, i, i + 1, SMALL_CHAR, BIG_CHAR);
-    }
-
-  for (i = 1; i < 8; ++i)
-    {
-      do_test (0, 16 << i, 2048, 0, MIDDLE_CHAR);
-      do_test (i, 16 << i, 2048, 0, MIDDLE_CHAR);
-    }
-
-  for (i = 1; i < 8; ++i)
-    {
-      do_test (i, 64, 256, 0, MIDDLE_CHAR);
-      do_test (i, 64, 256, 0, BIG_CHAR);
-    }
-
-  for (i = 0; i < 32; ++i)
-    {
-      do_test (0, i, i + 1, 0, MIDDLE_CHAR);
-      do_test (0, i, i + 1, 0, BIG_CHAR);
-    }
-
-  return ret;
-}
-
-#include "../test-skeleton.c"
+#include "bench-chr.h"
diff --git a/benchtests/bench-strchrnul.c b/benchtests/bench-strchrnul.c
index db5680c..38feda2 100644
--- a/benchtests/bench-strchrnul.c
+++ b/benchtests/bench-strchrnul.c
@@ -1,4 +1,4 @@
-/* Measure strchrnul function.
+/* Measure strchrnul functions.
    Copyright (C) 2013 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
@@ -16,5 +16,13 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#define USE_FOR_STRCHRNUL 1
-#include "bench-strchr.c"
+
+# define TEST_NAME "strchrnul"
+
+#define PROTO typedef char *(*proto_t) (const char *, int);
+#define IMPLS IMPL (strchrnul, 1)
+
+
+#define CALL2(impl, src, len) CALL (impl, src, 2)
+
+#include "bench-chr.h"
diff --git a/benchtests/bench-strlen.c b/benchtests/bench-strlen.c
index 44c9c2b..4060783 100644
--- a/benchtests/bench-strlen.c
+++ b/benchtests/bench-strlen.c
@@ -1,4 +1,4 @@
-/* Measure STRLEN functions.
+/* Measure strlen functions.
    Copyright (C) 2013 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
@@ -16,127 +16,13 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#define TEST_MAIN
-#ifndef WIDE
-# define TEST_NAME "strlen"
-#else
-# define TEST_NAME "wcslen"
-#endif
-#include "bench-string.h"
-
-#ifndef WIDE
-# define STRLEN strlen
-# define CHAR char
-# define MAX_CHAR CHAR_MAX
-#else
-# include <wchar.h>
-# define STRLEN wcslen
-# define CHAR wchar_t
-# define MAX_CHAR WCHAR_MAX
-#endif
-
-typedef size_t (*proto_t) (const CHAR *);
-
-size_t
-simple_STRLEN (const CHAR *s)
-{
-  const CHAR *p;
-
-  for (p = s; *p; ++p);
-  return p - s;
-}
-
-#ifndef WIDE
-size_t
-builtin_strlen (const CHAR *p)
-{
-  return __builtin_strlen (p);
-}
-IMPL (builtin_strlen, 0)
-#endif
-
-IMPL (simple_STRLEN, 0)
-IMPL (STRLEN, 1)
-
-
-static void
-do_one_test (impl_t *impl, const CHAR *s, size_t exp_len)
-{
-  size_t len = CALL (impl, s), i, iters = INNER_LOOP_ITERS;
-  timing_t start, stop, cur;
-
-  if (len != exp_len)
-    {
-      error (0, 0, "Wrong result in function %s %zd %zd", impl->name,
-	     len, exp_len);
-      ret = 1;
-      return;
-    }
-
-  TIMING_NOW (start);
-  for (i = 0; i < iters; ++i)
-    {
-      CALL (impl, s);
-    }
-  TIMING_NOW (stop);
-
-  TIMING_DIFF (cur, start, stop);
 
-  TIMING_PRINT_MEAN ((double) cur, (double) iters);
-}
-
-static void
-do_test (size_t align, size_t len)
-{
-  size_t i;
-
-  align &= 63;
-  if (align + sizeof(CHAR) * len >= page_size)
-    return;
-
-  CHAR *buf = (CHAR *) (buf1);
-
-  for (i = 0; i < len; ++i)
-    buf[align + i] = 1 + 11111 * i % MAX_CHAR;
-  buf[align + len] = 0;
-
-  printf ("Length %4zd, alignment %2zd:", len, align);
-
-  FOR_EACH_IMPL (impl, 0)
-    do_one_test (impl, (CHAR *) (buf + align), len);
-
-  putchar ('\n');
-}
-
-int
-test_main (void)
-{
-  size_t i;
-
-  test_init ();
-
-  printf ("%20s", "");
-  FOR_EACH_IMPL (impl, 0)
-    printf ("\t%s", impl->name);
-  putchar ('\n');
-
-  /* Checking with only 4 * N alignments for wcslen, other alignments are wrong for wchar_t type arrays*/
+# define TEST_NAME "strlen"
 
-  for (i = 1; i < 8; ++i)
-  {
-    do_test (sizeof(CHAR) * i, i);
-    do_test (0, i);
-  }
+#define PROTO typedef char *(*proto_t) (const char *);
+#define IMPLS IMPL (strlen, 1)
 
-  for (i = 2; i <= 12; ++i)
-    {
-      do_test (0, 1 << i);
-      do_test (sizeof(CHAR) * 7, 1 << i);
-      do_test (sizeof(CHAR) * i, 1 << i);
-      do_test (sizeof(CHAR) * i, (size_t)((1 << i) / 1.5));
-    }
 
-  return ret;
-}
+#define CALL2(impl, src, len) CALL (impl, src)
 
-#include "../test-skeleton.c"
+#include "bench-chr.h"
diff --git a/benchtests/bench-strnlen.c b/benchtests/bench-strnlen.c
index 793f9be..5f85c8f 100644
--- a/benchtests/bench-strnlen.c
+++ b/benchtests/bench-strnlen.c
@@ -1,4 +1,4 @@
-/* Measure strlen functions.
+/* Measure strchr functions.
    Copyright (C) 2013 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
@@ -16,117 +16,13 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#define TEST_MAIN
-#define TEST_NAME "strnlen"
-#include "bench-string.h"
 
-typedef size_t (*proto_t) (const char *, size_t);
-size_t simple_strnlen (const char *, size_t);
+# define TEST_NAME "strchr"
 
-IMPL (simple_strnlen, 0)
-IMPL (strnlen, 1)
+#define PROTO typedef char *(*proto_t) (const char *, size_t);
+#define IMPLS IMPL (strchr, 1)
 
-size_t
-simple_strnlen (const char *s, size_t maxlen)
-{
-  size_t i;
 
-  for (i = 0; i < maxlen && s[i]; ++i);
-  return i;
-}
+#define CALL2(impl, src, len) CALL (impl, src, len)
 
-static void
-do_one_test (impl_t *impl, const char *s, size_t maxlen, size_t exp_len)
-{
-  size_t len = CALL (impl, s, maxlen), i, iters = INNER_LOOP_ITERS;
-  timing_t start, stop, cur;
-
-  if (len != exp_len)
-    {
-      error (0, 0, "Wrong result in function %s %zd %zd", impl->name,
-	     len, exp_len);
-      ret = 1;
-      return;
-    }
-
-  TIMING_NOW (start);
-  for (i = 0; i < iters; ++i)
-    {
-      CALL (impl, s, maxlen);
-    }
-  TIMING_NOW (stop);
-
-  TIMING_DIFF (cur, start, stop);
-
-  TIMING_PRINT_MEAN ((double) cur, (double) iters);
-}
-
-static void
-do_test (size_t align, size_t len, size_t maxlen, int max_char)
-{
-  size_t i;
-
-  align &= 7;
-  if (align + len >= page_size)
-    return;
-
-  for (i = 0; i < len; ++i)
-    buf1[align + i] = 1 + 7 * i % max_char;
-  buf1[align + len] = 0;
-
-  printf ("Length %4zd, alignment %2zd:", len, align);
-
-  FOR_EACH_IMPL (impl, 0)
-    do_one_test (impl, (char *) (buf1 + align), maxlen, MIN (len, maxlen));
-
-  putchar ('\n');
-}
-
-int
-test_main (void)
-{
-  size_t i;
-
-  test_init ();
-
-  printf ("%20s", "");
-  FOR_EACH_IMPL (impl, 0)
-    printf ("\t%s", impl->name);
-  putchar ('\n');
-
-  for (i = 1; i < 8; ++i)
-    {
-      do_test (0, i, i - 1, 127);
-      do_test (0, i, i, 127);
-      do_test (0, i, i + 1, 127);
-    }
-
-  for (i = 1; i < 8; ++i)
-    {
-      do_test (i, i, i - 1, 127);
-      do_test (i, i, i, 127);
-      do_test (i, i, i + 1, 127);
-    }
-
-  for (i = 2; i <= 10; ++i)
-    {
-      do_test (0, 1 << i, 5000, 127);
-      do_test (1, 1 << i, 5000, 127);
-    }
-
-  for (i = 1; i < 8; ++i)
-    do_test (0, i, 5000, 255);
-
-  for (i = 1; i < 8; ++i)
-    do_test (i, i, 5000, 255);
-
-  for (i = 2; i <= 10; ++i)
-    {
-      do_test (0, 1 << i, 5000, 255);
-      do_test (1, 1 << i, 5000, 255);
-    }
-
-  return ret;
-}
-
-#include "../test-skeleton.c"
+#include "bench-chr.h"
diff --git a/benchtests/bench-strrchr.c b/benchtests/bench-strrchr.c
index 6a7aa84..0584781 100644
--- a/benchtests/bench-strrchr.c
+++ b/benchtests/bench-strrchr.c
@@ -1,4 +1,4 @@
-/* Measure STRCHR functions.
+/* Measure strrchr functions.
    Copyright (C) 2013 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
@@ -16,169 +16,13 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#define TEST_MAIN
-#ifdef WIDE
-# define TEST_NAME "wcsrchr"
-#else
-# define TEST_NAME "strrchr"
-#endif
-#include "bench-string.h"
-
-#ifdef WIDE
-# include <wchar.h>
-# define SIMPLE_STRRCHR simple_wcsrchr
-# define STRRCHR wcsrchr
-# define CHAR wchar_t
-# define UCHAR wchar_t
-# define BIG_CHAR WCHAR_MAX
-# define SMALL_CHAR 1273
-#else
-# define SIMPLE_STRRCHR simple_strrchr
-# define STRRCHR strrchr
-# define CHAR char
-# define UCHAR unsigned char
-# define BIG_CHAR CHAR_MAX
-# define SMALL_CHAR 127
-#endif
-
-typedef CHAR *(*proto_t) (const CHAR *, int);
-CHAR *SIMPLE_STRRCHR (const CHAR *, int);
-
-IMPL (SIMPLE_STRRCHR, 0)
-IMPL (STRRCHR, 1)
-
-CHAR *
-SIMPLE_STRRCHR (const CHAR *s, int c)
-{
-  const CHAR *ret = NULL;
-
-  for (; *s != '\0'; ++s)
-    if (*s == (CHAR) c)
-      ret = s;
-
-  return (CHAR *) (c == '\0' ? s : ret);
-}
-
-static void
-do_one_test (impl_t *impl, const CHAR *s, int c, CHAR *exp_res)
-{
-  CHAR *res = CALL (impl, s, c);
-  size_t i, iters = INNER_LOOP_ITERS;
-  timing_t start, stop, cur;
-
-  if (res != exp_res)
-    {
-      error (0, 0, "Wrong result in function %s %p %p", impl->name,
-	     res, exp_res);
-      ret = 1;
-      return;
-    }
-
-  TIMING_NOW (start);
-  for (i = 0; i < iters; ++i)
-    {
-      CALL (impl, s, c);
-    }
-  TIMING_NOW (stop);
-
-  TIMING_DIFF (cur, start, stop);
-
-  TIMING_PRINT_MEAN ((double) cur, (double) iters);
-}
-
-static void
-do_test (size_t align, size_t pos, size_t len, int seek_char, int max_char)
-/* For wcsrchr: align here means align not in bytes,
-   but in wchar_ts, in bytes it will equal to align * (sizeof (wchar_t))
-   len for wcschr here isn't in bytes but it's number of wchar_t symbols.  */
-{
-  size_t i;
-  CHAR *result;
-  CHAR *buf = (CHAR *) buf1;
 
-  align &= 7;
-  if ( (align + len) * sizeof(CHAR) >= page_size)
-    return;
-
-  for (i = 0; i < len; ++i)
-    {
-      buf[align + i] = (random () * random ()) & max_char;
-      if (!buf[align + i])
-	buf[align + i] = (random () * random ()) & max_char;
-      if (!buf[align + i])
-	buf[align + i] = 1;
-      if ((i > pos || pos >= len) && buf[align + i] == seek_char)
-	buf[align + i] = seek_char + 10 + (random () & 15);
-    }
-  buf[align + len] = 0;
-
-  if (pos < len)
-    {
-      buf[align + pos] = seek_char;
-      result = (CHAR *) (buf + align + pos);
-    }
-  else if (seek_char == 0)
-    result = (CHAR *) (buf + align + len);
-  else
-    result = NULL;
-
-  printf ("Length %4zd, alignment in bytes %2zd:", pos, align * sizeof(CHAR));
-
-  FOR_EACH_IMPL (impl, 0)
-    do_one_test (impl, (CHAR *) (buf + align), seek_char, result);
-
-  putchar ('\n');
-}
-
-int
-test_main (void)
-{
-  size_t i;
-
-  test_init ();
-
-  printf ("%20s", "");
-  FOR_EACH_IMPL (impl, 0)
-    printf ("\t%s", impl->name);
-  putchar ('\n');
-
-  for (i = 1; i < 8; ++i)
-    {
-      do_test (0, 16 << i, 2048, 23, SMALL_CHAR);
-      do_test (i, 16 << i, 2048, 23, SMALL_CHAR);
-    }
-
-  for (i = 1; i < 8; ++i)
-    {
-      do_test (i, 64, 256, 23, SMALL_CHAR);
-      do_test (i, 64, 256, 23, BIG_CHAR);
-    }
-
-  for (i = 0; i < 32; ++i)
-    {
-      do_test (0, i, i + 1, 23, SMALL_CHAR);
-      do_test (0, i, i + 1, 23, BIG_CHAR);
-    }
-
-  for (i = 1; i < 8; ++i)
-    {
-      do_test (0, 16 << i, 2048, 0, SMALL_CHAR);
-      do_test (i, 16 << i, 2048, 0, SMALL_CHAR);
-    }
+# define TEST_NAME "strrchr"
 
-  for (i = 1; i < 8; ++i)
-    {
-      do_test (i, 64, 256, 0, SMALL_CHAR);
-      do_test (i, 64, 256, 0, BIG_CHAR);
-    }
+#define PROTO typedef char *(*proto_t) (const char *, int);
+#define IMPLS IMPL (strrchr, 1)
 
-  for (i = 0; i < 32; ++i)
-    {
-      do_test (0, i, i + 1, 0, SMALL_CHAR);
-      do_test (0, i, i + 1, 0, BIG_CHAR);
-    }
 
-  return ret;
-}
+#define CALL2(impl, src, len) CALL (impl, src, 2)
 
-#include "../test-skeleton.c"
+#include "bench-chr.h"
-- 
1.7.10.4


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