summary refs log tree commit diff
path: root/benchtests/bench-memchr.c
diff options
context:
space:
mode:
authorWilco Dijkstra <wilco.dijkstra@arm.com>2023-03-03 12:54:45 +0000
committerWilco Dijkstra <wilco.dijkstra@arm.com>2023-03-08 18:36:25 +0000
commitdcfcb8e3928f68706e2bfa7527de363a899d2a69 (patch)
treee6c0676c34c7be018b41162a2a3c1ed0bfd6897d /benchtests/bench-memchr.c
parent73a284f618aa81d2bd1f93b299ac5dbf95f396b1 (diff)
downloadglibc-dcfcb8e3928f68706e2bfa7527de363a899d2a69.tar.gz
glibc-dcfcb8e3928f68706e2bfa7527de363a899d2a69.tar.xz
glibc-dcfcb8e3928f68706e2bfa7527de363a899d2a69.zip
Benchtests: Remove simple_mem(r)chr
Instead of benchmarking slow byte oriented loops, include the optimized
generic memchr/memrchr implementation.  Adjust iteration count to reduce
benchmark time.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
Diffstat (limited to 'benchtests/bench-memchr.c')
-rw-r--r--benchtests/bench-memchr.c40
1 files changed, 22 insertions, 18 deletions
diff --git a/benchtests/bench-memchr.c b/benchtests/bench-memchr.c
index b99995e293..90bd3879e3 100644
--- a/benchtests/bench-memchr.c
+++ b/benchtests/bench-memchr.c
@@ -16,6 +16,8 @@
    License along with the GNU C Library; if not, see
    <https://www.gnu.org/licenses/>.  */
 
+#include "json-lib.h"
+
 #ifndef WIDE
 # define SMALL_CHAR 127
 #else
@@ -31,35 +33,25 @@
 # endif /* WIDE */
 # include "bench-string.h"
 
-# ifndef WIDE
-#  define SIMPLE_MEMCHR simple_memchr
-# else
-#  define SIMPLE_MEMCHR simple_wmemchr
-# endif /* WIDE */
+typedef void *(*proto_t) (const void *, int, size_t);
 
-typedef CHAR *(*proto_t) (const CHAR *, int, size_t);
-CHAR *SIMPLE_MEMCHR (const CHAR *, int, size_t);
+void *
+generic_memchr (const void *, int, size_t);
 
-IMPL (SIMPLE_MEMCHR, 0)
 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;
-}
+# ifndef WIDE
+IMPL (generic_memchr, 0)
+# endif
+
 #endif /* !USE_AS_MEMRCHR */
 
-#include "json-lib.h"
 
 static void
 do_one_test (json_ctx_t *json_ctx, impl_t *impl, const CHAR *s, int c,
 	     size_t n)
 {
-  size_t i, iters = INNER_LOOP_ITERS_LARGE;
+  size_t i, iters = INNER_LOOP_ITERS;
   timing_t start, stop, cur;
 
   TIMING_NOW (start);
@@ -250,3 +242,15 @@ test_main (void)
 }
 
 #include <support/test-driver.c>
+
+#ifndef WIDE
+# ifndef USE_AS_MEMRCHR
+#  undef MEMCHR
+#  define MEMCHR generic_memchr
+#  include <string/memchr.c>
+# else
+#  undef MEMRCHR
+#  define MEMRCHR generic_memrchr
+#  include <string/memrchr.c>
+# endif
+#endif