about summary refs log tree commit diff
path: root/benchtests/bench-stpncpy.c
diff options
context:
space:
mode:
authorWilco Dijkstra <wdijkstr@arm.com>2019-04-09 11:54:34 +0100
committerWilco Dijkstra <wdijkstr@arm.com>2019-04-09 11:54:34 +0100
commit648279f4af423c4783ec1dfa63cb7b46a7640217 (patch)
treefb9277130379baddc55546b600f2c1b0d4b947ad /benchtests/bench-stpncpy.c
parent93eebae5168e5cf2abfb4b6266e3fb2ab860cd60 (diff)
downloadglibc-648279f4af423c4783ec1dfa63cb7b46a7640217.tar.gz
glibc-648279f4af423c4783ec1dfa63cb7b46a7640217.tar.xz
glibc-648279f4af423c4783ec1dfa63cb7b46a7640217.zip
Improve string benchtests
Replace slow byte-oriented tests in several string benchmarks with the
generic implementations from the string/ directory so the comparisons
are more realistic and useful.

	* benchtests/bench-stpcpy.c (SIMPLE_STPCPY): Remove function.
	(generic_stpcpy): New function.
	* benchtests/bench-stpncpy.c (SIMPLE_STPNCPY): Remove function.
	(generic_stpncpy): New function.
	* benchtests/bench-strcat.c (SIMPLE_STRCAT): Remove function.
	(generic_strcat): New function.
	* benchtests/bench-strcpy.c (SIMPLE_STRCPY): Remove function.
	(generic_strcpy): New function.
	* benchtests/bench-strncat.c (SIMPLE_STRNCAT): Remove function.
	(STUPID_STRNCAT): Remove function.
	(generic_strncat): New function.
	* benchtests/bench-strncpy.c (SIMPLE_STRNCPY): Remove function.
	(STUPID_STRNCPY): Remove function.
	(generic_strncpy): New function.
	* benchtests/bench-strnlen.c (SIMPLE_STRNLEN): Remove function.
	(generic_strnlen): New function.
	(memchr_strnlen): New function.
	* benchtests/bench-strlen.c (generic_strlen): Define for WIDE.
	(memchr_strlen): Likewise.
Diffstat (limited to 'benchtests/bench-stpncpy.c')
-rw-r--r--benchtests/bench-stpncpy.c47
1 files changed, 10 insertions, 37 deletions
diff --git a/benchtests/bench-stpncpy.c b/benchtests/bench-stpncpy.c
index 0470695889..c4c6b65bb7 100644
--- a/benchtests/bench-stpncpy.c
+++ b/benchtests/bench-stpncpy.c
@@ -22,49 +22,22 @@
 # define TEST_NAME "stpncpy"
 #else
 # define TEST_NAME "wcpncpy"
+# define generic_stpncpy generic_wcpncpy
 #endif /* WIDE */
 #include "bench-string.h"
-#ifndef WIDE
-# define SIMPLE_STPNCPY simple_stpncpy
-# define STUPID_STPNCPY stupid_stpncpy
-#else
-# define SIMPLE_STPNCPY simple_wcpncpy
-# define STUPID_STPNCPY stupid_wcpncpy
-#endif /* WIDE */
-
-CHAR *SIMPLE_STPNCPY (CHAR *, const CHAR *, size_t);
-CHAR *STUPID_STPNCPY (CHAR *, const CHAR *, size_t);
-
-IMPL (STUPID_STPNCPY, 0)
-IMPL (SIMPLE_STPNCPY, 0)
-IMPL (STPNCPY, 1)
-
-CHAR *
-SIMPLE_STPNCPY (CHAR *dst, const CHAR *src, size_t n)
-{
-  while (n--)
-    if ((*dst++ = *src++) == '\0')
-      {
-	size_t i;
-
-	for (i = 0; i < n; ++i)
-	  dst[i] = '\0';
-	return dst - 1;
-      }
-  return dst;
-}
 
 CHAR *
-STUPID_STPNCPY (CHAR *dst, const CHAR *src, size_t n)
+generic_stpncpy (CHAR *dst, const CHAR *src, size_t n)
 {
   size_t nc = STRNLEN (src, n);
-  size_t i;
-
-  for (i = 0; i < nc; ++i)
-    dst[i] = src[i];
-  for (; i < n; ++i)
-    dst[i] = '\0';
-  return dst + nc;
+  MEMCPY (dst, src, nc);
+  dst += nc;
+  if (nc == n)
+    return dst;
+  return MEMSET (dst, 0, n - nc);
 }
 
+IMPL (STPNCPY, 1)
+IMPL (generic_stpncpy, 0)
+
 #include "bench-strncpy.c"