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


Instead of benchmarking a slow byte oriented loops, include the optimized generic
memchr/memrchr implementation. Adjust iteration count to reduce benchmark time.

---

diff --git a/benchtests/bench-memchr.c b/benchtests/bench-memchr.c
index b99995e293f30a0ddbc68722552764b804521eb4..90bd3879e32e81950c633cf7f2d4f3f6a92d2311 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
diff --git a/benchtests/bench-memrchr.c b/benchtests/bench-memrchr.c
index 4f594ee7cdbe05c3ec4425b5d922ce2b9912b660..1f8c8845037db84ca0d4201ed991a09cdf19d57d 100644
--- a/benchtests/bench-memrchr.c
+++ b/benchtests/bench-memrchr.c
@@ -21,20 +21,12 @@
 #include "bench-string.h"
 
 typedef char *(*proto_t) (const char *, int, size_t);
-char *simple_memrchr (const char *, int, size_t);
 
-IMPL (simple_memrchr, 0)
-IMPL (memrchr, 1)
+void *
+generic_memrchr (const void *, int, size_t);
 
-char *
-simple_memrchr (const char *s, int c, size_t n)
-{
-  s = s + n;
-  while (n--)
-    if (*--s == (char) c)
-      return (char *) s;
-  return NULL;
-}
+IMPL (memrchr, 1)
+IMPL (generic_memrchr, 0)
 
 #define USE_AS_MEMRCHR
 #include "bench-memchr.c"


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

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



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


LGTM, thanks.

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

> 
> ---
> 
> diff --git a/benchtests/bench-memchr.c b/benchtests/bench-memchr.c
> index b99995e293f30a0ddbc68722552764b804521eb4..90bd3879e32e81950c633cf7f2d4f3f6a92d2311 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
> diff --git a/benchtests/bench-memrchr.c b/benchtests/bench-memrchr.c
> index 4f594ee7cdbe05c3ec4425b5d922ce2b9912b660..1f8c8845037db84ca0d4201ed991a09cdf19d57d 100644
> --- a/benchtests/bench-memrchr.c
> +++ b/benchtests/bench-memrchr.c
> @@ -21,20 +21,12 @@
>  #include "bench-string.h"
>  
>  typedef char *(*proto_t) (const char *, int, size_t);
> -char *simple_memrchr (const char *, int, size_t);
>  
> -IMPL (simple_memrchr, 0)
> -IMPL (memrchr, 1)
> +void *
> +generic_memrchr (const void *, int, size_t);
>  
> -char *
> -simple_memrchr (const char *s, int c, size_t n)
> -{
> -  s = s + n;
> -  while (n--)
> -    if (*--s == (char) c)
> -      return (char *) s;
> -  return NULL;
> -}
> +IMPL (memrchr, 1)
> +IMPL (generic_memrchr, 0)
>  
>  #define USE_AS_MEMRCHR
>  #include "bench-memchr.c"
> 

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

end of thread, other threads:[~2023-03-08 15:18 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:44 [PATCH] Benchtests: Remove simple_mem(r)chr Wilco Dijkstra
2023-03-08 15:18 ` 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).