public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Benchtests: Remove simple_str(r)chr
@ 2023-03-08 10:57 Wilco Dijkstra
  2023-03-08 15:23 ` Adhemerval Zanella Netto
  0 siblings, 1 reply; 2+ messages in thread
From: Wilco Dijkstra @ 2023-03-08 10:57 UTC (permalink / raw)
  To: 'GNU C Library'


Instead of benchmarking slow byte oriented loops, include the optimized generic
strchr and strrchr implementation. Adjust iteration count to reduce benchmark time.

---

diff --git a/benchtests/bench-strchr.c b/benchtests/bench-strchr.c
index 420930d558e4c6f9de0eb4fc0bff4b536e4cfab3..116ec197603cc784e36d2a990eb9e47b7e90e74f 100644
--- a/benchtests/bench-strchr.c
+++ b/benchtests/bench-strchr.c
@@ -39,7 +39,6 @@
 # ifdef USE_FOR_STRCHRNUL
 #  undef STRCHR
 #  define STRCHR strchrnul
-#  define simple_STRCHR simple_STRCHRNUL
 # endif /* !USE_FOR_STRCHRNUL */
 # define MIDDLE_CHAR 127
 # define SMALL_CHAR 23
@@ -47,7 +46,6 @@
 # ifdef USE_FOR_STRCHRNUL
 #  undef STRCHR
 #  define STRCHR wcschrnul
-#  define simple_STRCHR simple_WCSCHRNUL
 # endif /* !USE_FOR_STRCHRNUL */
 # define MIDDLE_CHAR 1121
 # define SMALL_CHAR 851
@@ -67,18 +65,19 @@
 
 typedef CHAR *(*proto_t) (const CHAR *, int);
 
-CHAR *
-simple_STRCHR (const CHAR *s, int c)
-{
-  for (; *s != (CHAR) c; ++s)
-    if (*s == '\0')
-      return NULLRET ((CHAR *) s);
-  return (CHAR *) s;
-}
-
-IMPL (simple_STRCHR, 0)
 IMPL (STRCHR, 1)
 
+#ifndef WIDE
+char *generic_strchr (const char *, int);
+char *generic_strchrnul (const char *, int);
+
+# ifndef USE_FOR_STRCHRNUL
+IMPL (generic_strchr, 0)
+# else
+IMPL (generic_strchrnul, 0)
+# endif
+#endif
+
 #ifndef USE_FOR_STRCHRNUL
 /* Random benchmarks for strchr (if return is CHAR or NULL).  The
    rational for the benchmark is returning null/char can be done with
@@ -97,7 +96,7 @@ static void __attribute__ ((noinline, noclone))
 do_one_rand_plus_branch_test (json_ctx_t *json_ctx, impl_t *impl,
                               const CHAR *s, const CHAR *c)
 {
-  size_t i, iters = INNER_LOOP_ITERS_LARGE;
+  size_t i, iters = INNER_LOOP_ITERS8;
   int must_execute = 0;
   timing_t start, stop, cur;
   TIMING_NOW (start);
@@ -122,7 +121,7 @@ static void __attribute__ ((noinline, noclone))
 do_one_rand_test (json_ctx_t *json_ctx, impl_t *impl, const CHAR *s,
                   const CHAR *c)
 {
-  size_t i, iters = INNER_LOOP_ITERS_LARGE;
+  size_t i, iters = INNER_LOOP_ITERS8;
   timing_t start, stop, cur;
   TIMING_NOW (start);
   for (i = 0; i < iters; ++i)
@@ -210,7 +209,7 @@ static void
 do_one_test (json_ctx_t *json_ctx, impl_t *impl, const CHAR *s, int c,
              const CHAR *exp_res)
 {
-  size_t i, iters = INNER_LOOP_ITERS_LARGE;
+  size_t i, iters = INNER_LOOP_ITERS8;
   timing_t start, stop, cur;
   const CHAR *res = CALL (impl, s, c);
   if (res != exp_res)
@@ -401,3 +400,12 @@ test_main (void)
 }
 
 #include <support/test-driver.c>
+
+#ifndef WIDE
+# undef STRCHRNUL
+# define STRCHRNUL generic_strchrnul
+# undef STRCHR
+# define STRCHR generic_strchr
+# include <string/strchrnul.c>
+# include <string/strchr.c>
+#endif
diff --git a/benchtests/bench-strrchr.c b/benchtests/bench-strrchr.c
index a33a657a275416b0cb0c42ba2689e3685c1b62aa..f846797770f9384fcde8eb3d66b3b8c720866452 100644
--- a/benchtests/bench-strrchr.c
+++ b/benchtests/bench-strrchr.c
@@ -28,30 +28,20 @@
 #define BIG_CHAR MAX_CHAR
 
 #ifdef WIDE
-# define SIMPLE_STRRCHR simple_wcsrchr
 # define SMALL_CHAR 1273
 #else
-# define SIMPLE_STRRCHR simple_strrchr
 # define SMALL_CHAR 127
-#endif
 
-typedef CHAR *(*proto_t) (const CHAR *, int);
-CHAR *SIMPLE_STRRCHR (const CHAR *, int);
+char *
+generic_strrchr (const char *, int);
 
-IMPL (SIMPLE_STRRCHR, 0)
-IMPL (STRRCHR, 1)
+IMPL (generic_strrchr, 0)
 
-CHAR *
-SIMPLE_STRRCHR (const CHAR *s, int c)
-{
-  const CHAR *ret = NULL;
+#endif
 
-  for (; *s != '\0'; ++s)
-    if (*s == (CHAR) c)
-      ret = s;
+typedef CHAR *(*proto_t) (const CHAR *, int);
 
-  return (CHAR *) (c == '\0' ? s : ret);
-}
+IMPL (STRRCHR, 1)
 
 static void
 do_one_test (json_ctx_t *json_ctx, impl_t *impl, const CHAR *s, int c,
@@ -237,3 +227,12 @@ test_main (void)
 }
 
 #include <support/test-driver.c>
+
+#define weak_alias(X,Y)
+#define libc_hidden_builtin_def(X)
+#ifndef WIDE
+# undef STRRCHR
+# define STRRCHR generic_strrchr
+# define __memrchr memrchr
+# include <string/strrchr.c>
+#endif


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] Benchtests: Remove simple_str(r)chr
  2023-03-08 10:57 [PATCH] Benchtests: Remove simple_str(r)chr Wilco Dijkstra
@ 2023-03-08 15:23 ` Adhemerval Zanella Netto
  0 siblings, 0 replies; 2+ messages in thread
From: Adhemerval Zanella Netto @ 2023-03-08 15:23 UTC (permalink / raw)
  To: Wilco Dijkstra, 'GNU C Library'



On 08/03/23 07:57, Wilco Dijkstra via Libc-alpha wrote:
> 
> Instead of benchmarking slow byte oriented loops, include the optimized generic
> strchr and strrchr implementation. Adjust iteration count to reduce benchmark time.

LGTM, thanks.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>


> 
> ---
> 
> diff --git a/benchtests/bench-strchr.c b/benchtests/bench-strchr.c
> index 420930d558e4c6f9de0eb4fc0bff4b536e4cfab3..116ec197603cc784e36d2a990eb9e47b7e90e74f 100644
> --- a/benchtests/bench-strchr.c
> +++ b/benchtests/bench-strchr.c
> @@ -39,7 +39,6 @@
>  # ifdef USE_FOR_STRCHRNUL
>  #  undef STRCHR
>  #  define STRCHR strchrnul
> -#  define simple_STRCHR simple_STRCHRNUL
>  # endif /* !USE_FOR_STRCHRNUL */
>  # define MIDDLE_CHAR 127
>  # define SMALL_CHAR 23
> @@ -47,7 +46,6 @@
>  # ifdef USE_FOR_STRCHRNUL
>  #  undef STRCHR
>  #  define STRCHR wcschrnul
> -#  define simple_STRCHR simple_WCSCHRNUL
>  # endif /* !USE_FOR_STRCHRNUL */
>  # define MIDDLE_CHAR 1121
>  # define SMALL_CHAR 851
> @@ -67,18 +65,19 @@
>  
>  typedef CHAR *(*proto_t) (const CHAR *, int);
>  
> -CHAR *
> -simple_STRCHR (const CHAR *s, int c)
> -{
> -  for (; *s != (CHAR) c; ++s)
> -    if (*s == '\0')
> -      return NULLRET ((CHAR *) s);
> -  return (CHAR *) s;
> -}
> -
> -IMPL (simple_STRCHR, 0)
>  IMPL (STRCHR, 1)
>  
> +#ifndef WIDE
> +char *generic_strchr (const char *, int);
> +char *generic_strchrnul (const char *, int);
> +
> +# ifndef USE_FOR_STRCHRNUL
> +IMPL (generic_strchr, 0)
> +# else
> +IMPL (generic_strchrnul, 0)
> +# endif
> +#endif
> +
>  #ifndef USE_FOR_STRCHRNUL
>  /* Random benchmarks for strchr (if return is CHAR or NULL).  The
>     rational for the benchmark is returning null/char can be done with
> @@ -97,7 +96,7 @@ static void __attribute__ ((noinline, noclone))
>  do_one_rand_plus_branch_test (json_ctx_t *json_ctx, impl_t *impl,
>                                const CHAR *s, const CHAR *c)
>  {
> -  size_t i, iters = INNER_LOOP_ITERS_LARGE;
> +  size_t i, iters = INNER_LOOP_ITERS8;
>    int must_execute = 0;
>    timing_t start, stop, cur;
>    TIMING_NOW (start);
> @@ -122,7 +121,7 @@ static void __attribute__ ((noinline, noclone))
>  do_one_rand_test (json_ctx_t *json_ctx, impl_t *impl, const CHAR *s,
>                    const CHAR *c)
>  {
> -  size_t i, iters = INNER_LOOP_ITERS_LARGE;
> +  size_t i, iters = INNER_LOOP_ITERS8;
>    timing_t start, stop, cur;
>    TIMING_NOW (start);
>    for (i = 0; i < iters; ++i)
> @@ -210,7 +209,7 @@ static void
>  do_one_test (json_ctx_t *json_ctx, impl_t *impl, const CHAR *s, int c,
>               const CHAR *exp_res)
>  {
> -  size_t i, iters = INNER_LOOP_ITERS_LARGE;
> +  size_t i, iters = INNER_LOOP_ITERS8;
>    timing_t start, stop, cur;
>    const CHAR *res = CALL (impl, s, c);
>    if (res != exp_res)
> @@ -401,3 +400,12 @@ test_main (void)
>  }
>  
>  #include <support/test-driver.c>
> +
> +#ifndef WIDE
> +# undef STRCHRNUL
> +# define STRCHRNUL generic_strchrnul
> +# undef STRCHR
> +# define STRCHR generic_strchr
> +# include <string/strchrnul.c>
> +# include <string/strchr.c>
> +#endif
> diff --git a/benchtests/bench-strrchr.c b/benchtests/bench-strrchr.c
> index a33a657a275416b0cb0c42ba2689e3685c1b62aa..f846797770f9384fcde8eb3d66b3b8c720866452 100644
> --- a/benchtests/bench-strrchr.c
> +++ b/benchtests/bench-strrchr.c
> @@ -28,30 +28,20 @@
>  #define BIG_CHAR MAX_CHAR
>  
>  #ifdef WIDE
> -# define SIMPLE_STRRCHR simple_wcsrchr
>  # define SMALL_CHAR 1273
>  #else
> -# define SIMPLE_STRRCHR simple_strrchr
>  # define SMALL_CHAR 127
> -#endif
>  
> -typedef CHAR *(*proto_t) (const CHAR *, int);
> -CHAR *SIMPLE_STRRCHR (const CHAR *, int);
> +char *
> +generic_strrchr (const char *, int);
>  
> -IMPL (SIMPLE_STRRCHR, 0)
> -IMPL (STRRCHR, 1)
> +IMPL (generic_strrchr, 0)
>  
> -CHAR *
> -SIMPLE_STRRCHR (const CHAR *s, int c)
> -{
> -  const CHAR *ret = NULL;
> +#endif
>  
> -  for (; *s != '\0'; ++s)
> -    if (*s == (CHAR) c)
> -      ret = s;
> +typedef CHAR *(*proto_t) (const CHAR *, int);
>  
> -  return (CHAR *) (c == '\0' ? s : ret);
> -}
> +IMPL (STRRCHR, 1)
>  
>  static void
>  do_one_test (json_ctx_t *json_ctx, impl_t *impl, const CHAR *s, int c,
> @@ -237,3 +227,12 @@ test_main (void)
>  }
>  
>  #include <support/test-driver.c>
> +
> +#define weak_alias(X,Y)
> +#define libc_hidden_builtin_def(X)
> +#ifndef WIDE
> +# undef STRRCHR
> +# define STRRCHR generic_strrchr
> +# define __memrchr memrchr
> +# include <string/strrchr.c>
> +#endif
> 

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-03-08 15:23 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-08 10:57 [PATCH] Benchtests: Remove simple_str(r)chr Wilco Dijkstra
2023-03-08 15:23 ` Adhemerval Zanella Netto

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).