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]

Re: [PATCH 2/2] Add *chr benchtests


On Fri, Sep 06, 2013 at 04:32:35PM +0200, OndÅej BÃlka wrote:
> On Fri, Sep 06, 2013 at 11:32:06AM +0100, Will Newton wrote:
> > On 6 September 2013 09:32, OndÅej BÃlka <neleai@seznam.cz> wrote:
> > > 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.
> > 
> > The description does not mention that things such as test output
> > change and that the randomisation changes have been added. Again I
> > feel like it would be much easier to review the changes if the
> > functional and non-functional changes in the patch were separated.
> > 
> > >  9 files changed, 179 insertions(+), 785 deletions(-)
> > 
> > That is a lot of lines to go through to figure out whether a change is
> > functional or not.
> 
> It simple, there is too much of redundant and duplicate code in 
> existing benchmarks so this is rewrite.
> 
And new version is here.


	* benchtests/bench-chr.c: New file.
	* benchtests/bench-memchr.c: Likewise.
	* benchtests/bench-memrchr.c: Likewise.
	* benchtests/bench-rawmemchr.c: Likewise.
	* benchtests/bench-strchr.c: Likewise.
	* benchtests/bench-strlen.c: Likewise.
	* benchtests/bench-strnlen.c: Likewise.
	* benchtests/bench-strrchr.c: Likewise.

---
 benchtests/bench-chr.c       | 178 +++++++++++++++++++++++++++++++++++++++++++
 benchtests/bench-memchr.c    |  26 +++++++
 benchtests/bench-memrchr.c   |  26 +++++++
 benchtests/bench-rawmemchr.c |  26 +++++++
 benchtests/bench-strchr.c    |  22 ++++++
 benchtests/bench-strlen.c    |  26 +++++++
 benchtests/bench-strnlen.c   |  26 +++++++
 benchtests/bench-strrchr.c   |  22 ++++++
 8 files changed, 352 insertions(+)
 create mode 100644 benchtests/bench-chr.c
 create mode 100644 benchtests/bench-memchr.c
 create mode 100644 benchtests/bench-memrchr.c
 create mode 100644 benchtests/bench-rawmemchr.c
 create mode 100644 benchtests/bench-strchr.c
 create mode 100644 benchtests/bench-strlen.c
 create mode 100644 benchtests/bench-strnlen.c
 create mode 100644 benchtests/bench-strrchr.c

diff --git a/benchtests/bench-chr.c b/benchtests/bench-chr.c
new file mode 100644
index 0000000..c1fbed0
--- /dev/null
+++ b/benchtests/bench-chr.c
@@ -0,0 +1,178 @@
+/* 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 MIN_PAGE_SIZE (1<<22)
+#define TEST_MAIN
+#include "bench-string.h"
+#define CACHE_LINE_SIZE 64
+
+#ifdef WIDE
+# define CHAR wchar_t
+#else
+# define CHAR char
+#endif
+
+#if defined AS_STRLEN
+typedef char *(*proto_t) (const char *);
+#elif defined AS_STRNLEN
+typedef char *(*proto_t) (const char *, size_t);
+#elif defined AS_RAWMEMCHR
+typedef char *(*proto_t) (const char *, int);
+#elif defined AS_STRCHR || defined AS_STRRCHR  
+typedef char *(*proto_t) (const char *, int);
+#else
+typedef char *(*proto_t) (const char *, int, size_t);
+#endif
+
+IMPL (FN_NAME, 1);
+
+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], found[INNER_LOOP_ITERS];
+
+  for (i = 0; i < iters; ++i)
+    {
+      srcs[i] = ((CHAR *) buf1) + 
+                rand_r (&r_seed) % (MIN_PAGE_SIZE / sizeof (CHAR) / 2);
+      found[i] = (rand_r (&r_seed) % 2) ? 2 : 0;
+      if (aligned != -1) /* Align pointers. */
+        srcs[i] = (CHAR *) (((uintptr_t) srcs[i]) & ~(CACHE_LINE_SIZE -1)) + aligned;
+    }
+
+  TIMING_NOW (start);
+  for (i = 0; i < iters; ++i)
+    {
+      CHAR orig1 = srcs[i][len], orig2 = srcs[i][len + 1];
+#ifndef AS_MEMRCHR
+      srcs[i][len] = found[i];
+#endif
+      srcs[i][len + 1] = 0;
+
+#if defined AS_STRLEN
+      CALL (impl, srcs[i]);
+#elif defined AS_STRNLEN
+      CALL (impl, srcs[i], len);
+#elif defined AS_RAWMEMCHR
+      CALL (impl, srcs[i], 0);
+#elif defined AS_STRRCHR  
+      CALL (impl, srcs[i], 2);
+#elif defined AS_STRCHR 
+      CALL (impl, srcs[i], 18);
+#else
+      CALL (impl, srcs[i], 18, len);
+#endif
+
+      srcs[i][len] = orig1;
+      srcs[i][len + 1] = orig2;
+    }
+  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 ("%7zd, ",len);
+  if (aligned == -1)
+    printf ("rnd,    ");
+  else
+    printf("%3zd,    ",aligned);
+
+  FOR_EACH_IMPL (impl, 0)
+    do_one_test (impl, aligned, len);
+
+  putchar ('\n');
+}
+
+int
+test_main (void)
+{
+  size_t i;
+
+  test_init ();
+
+  static unsigned int r_seed = 42;
+  for (i = 0; i < MIN_PAGE_SIZE; i++)
+    {
+      buf1[i] = rand_r(&r_seed) % 16 + 1;
+    }
+
+  printf ("  Length, alignement");
+  FOR_EACH_IMPL (impl, 0)
+    printf (" %10s", impl->name);
+  putchar ('\n');
+
+  for (i = 0; i < 64; ++i)
+    {
+      do_test (0, i);
+      do_test (-1, i);
+    }
+
+  for (i = 0; i < 18; ++i)
+    {
+      do_test (0, 1 << i);
+      do_test (-1, 1 << i);
+    }
+
+#ifdef AS_STRRCHR
+  puts ("Probability of character is now 1/128");
+  for (i = 0; i < MIN_PAGE_SIZE; i++)
+    {
+      buf1[i] = rand_r(&r_seed) % 16 + 1;
+    }
+
+  for (i = 0; i < 64; ++i)
+    {
+      do_test (0, i);
+      do_test (-1, i);
+    }
+
+  for (i = 0; i < 18; ++i)
+    {
+      do_test (0, 1 << i);
+      do_test (-1, 1 << i);
+    }
+
+#endif
+
+  for (i = 0; i < CACHE_LINE_SIZE; ++i)
+    {
+      do_test (i, 16);
+    }
+
+  for (i = 0; i < CACHE_LINE_SIZE; ++i)
+    {
+      do_test (i, 32);
+    }
+
+  for (i = 0; i < CACHE_LINE_SIZE; ++i)
+    {
+      do_test (i, 64);
+    }
+  return ret;
+}
+
+#include "../test-skeleton.c"
diff --git a/benchtests/bench-memchr.c b/benchtests/bench-memchr.c
new file mode 100644
index 0000000..46e0f2d
--- /dev/null
+++ b/benchtests/bench-memchr.c
@@ -0,0 +1,26 @@
+/* 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 FN_NAME memchr
+#define TEST_NAME "memchr"
+#define AS_MEMCHR
+#include "bench-chr.c"
diff --git a/benchtests/bench-memrchr.c b/benchtests/bench-memrchr.c
new file mode 100644
index 0000000..88f30a0
--- /dev/null
+++ b/benchtests/bench-memrchr.c
@@ -0,0 +1,26 @@
+/* Measure memrchr 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 FN_NAME memrchr
+#define TEST_NAME "memrchr"
+#define AS_MEMRCHR
+#include "bench-chr.c"
diff --git a/benchtests/bench-rawmemchr.c b/benchtests/bench-rawmemchr.c
new file mode 100644
index 0000000..d7d71b7
--- /dev/null
+++ b/benchtests/bench-rawmemchr.c
@@ -0,0 +1,26 @@
+/* Measure rawmemchr 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 FN_NAME rawmemchr
+#define TEST_NAME "rawmemchr"
+#define AS_RAWMEMCHR
+#include "bench-chr.c"
diff --git a/benchtests/bench-strchr.c b/benchtests/bench-strchr.c
new file mode 100644
index 0000000..b2cb772
--- /dev/null
+++ b/benchtests/bench-strchr.c
@@ -0,0 +1,22 @@
+/* Measure strchr 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 FN_NAME strchr
+#define TEST_NAME "strchr"
+#define AS_STRCHR
+#include "bench-chr.c"
diff --git a/benchtests/bench-strlen.c b/benchtests/bench-strlen.c
new file mode 100644
index 0000000..158a813
--- /dev/null
+++ b/benchtests/bench-strlen.c
@@ -0,0 +1,26 @@
+/* Measure strchr 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 FN_NAME strchr
+#define TEST_NAME "strchr"
+#define AS_STRCHR
+#include "bench-chr.c"
diff --git a/benchtests/bench-strnlen.c b/benchtests/bench-strnlen.c
new file mode 100644
index 0000000..158a813
--- /dev/null
+++ b/benchtests/bench-strnlen.c
@@ -0,0 +1,26 @@
+/* Measure strchr 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 FN_NAME strchr
+#define TEST_NAME "strchr"
+#define AS_STRCHR
+#include "bench-chr.c"
diff --git a/benchtests/bench-strrchr.c b/benchtests/bench-strrchr.c
new file mode 100644
index 0000000..e021cf6
--- /dev/null
+++ b/benchtests/bench-strrchr.c
@@ -0,0 +1,22 @@
+/* Measure strrchr 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 FN_NAME strrchr
+#define TEST_NAME "strrchr"
+#define AS_STRRCHR
+#include "bench-chr.c"
-- 
1.8.3.2


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