public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH v1] Benchtest: Add additional benchmarks for strlen and strnlen
@ 2022-09-28 19:20 Noah Goldstein
  2022-09-28 19:25 ` H.J. Lu
  2022-09-28 19:26 ` Sunil Pandey
  0 siblings, 2 replies; 4+ messages in thread
From: Noah Goldstein @ 2022-09-28 19:20 UTC (permalink / raw)
  To: libc-alpha; +Cc: goldstein.w.n, hjl.tools, carlos

Current benchmarks are missing many cases in the mid-length range
which is often the hottest size range.
---
 benchtests/bench-strlen.c  | 33 ++++++++++++++++++++---
 benchtests/bench-strnlen.c | 55 +++++++++++++++++++++++++++++++++++---
 2 files changed, 81 insertions(+), 7 deletions(-)

diff --git a/benchtests/bench-strlen.c b/benchtests/bench-strlen.c
index 602e52ee83..696e4541d7 100644
--- a/benchtests/bench-strlen.c
+++ b/benchtests/bench-strlen.c
@@ -128,10 +128,10 @@ test_main (void)
   /* Checking with only 4 * N alignments for wcslen, other alignments are wrong for wchar_t type arrays*/
 
   for (i = 1; i < 8; ++i)
-  {
-    do_test (&json_ctx, sizeof (CHAR) * i, i);
-    do_test (&json_ctx, 0, i);
-  }
+    {
+      do_test (&json_ctx, sizeof (CHAR) * i, i);
+      do_test (&json_ctx, 0, i);
+    }
 
   for (i = 2; i <= 12; ++i)
     {
@@ -141,6 +141,31 @@ test_main (void)
       do_test (&json_ctx, sizeof (CHAR) * i, (size_t)((1 << i) / 1.5));
     }
 
+  for (i = 0; i < 512; i += 32)
+    {
+      do_test (&json_ctx, 0, i / sizeof (CHAR));
+    }
+
+  for (i = 512; i < 1024; i += 64)
+    {
+      do_test (&json_ctx, 0, i / sizeof (CHAR));
+    }
+
+  for (i = 1024; i < 2048; i += 128)
+    {
+      do_test (&json_ctx, 0, i / sizeof (CHAR));
+    }
+
+  for (i = 2048; i < 4096; i += 256)
+    {
+      do_test (&json_ctx, 0, i / sizeof (CHAR));
+    }
+
+  for (i = 4096; i < 8192; i += 512)
+    {
+      do_test (&json_ctx, 0, i / sizeof (CHAR));
+    }
+
   json_array_end (&json_ctx);
   json_attr_object_end (&json_ctx);
   json_attr_object_end (&json_ctx);
diff --git a/benchtests/bench-strnlen.c b/benchtests/bench-strnlen.c
index 2cd561dfd5..13b46b3f57 100644
--- a/benchtests/bench-strnlen.c
+++ b/benchtests/bench-strnlen.c
@@ -63,6 +63,11 @@ do_one_test (json_ctx_t *json_ctx, impl_t *impl, const CHAR *s, size_t maxlen,
       ret = 1;
       return;
     }
+  /* Warmup.  */
+  for (i = 0; i < iters / 16; ++i)
+    {
+      CALL (impl, s, maxlen);
+    }
 
   TIMING_NOW (start);
   for (i = 0; i < iters; ++i)
@@ -110,7 +115,7 @@ do_test (json_ctx_t *json_ctx, size_t align, size_t len, size_t maxlen,
 int
 test_main (void)
 {
-  size_t i;
+  size_t i, j;
   json_ctx_t json_ctx;
 
   test_init ();
@@ -131,6 +136,19 @@ test_main (void)
 
   json_array_begin (&json_ctx, "results");
 
+  for (i = 0; i <= 1; ++i)
+    {
+      do_test (&json_ctx, i, 1, 128, MIDDLE_CHAR);
+      do_test (&json_ctx, i, 128, 1, MIDDLE_CHAR);
+      do_test (&json_ctx, i, 1, 2, MIDDLE_CHAR);
+      do_test (&json_ctx, i, 2, 1, MIDDLE_CHAR);
+
+      do_test (&json_ctx, 32 + i, 1, 128, MIDDLE_CHAR);
+      do_test (&json_ctx, 32 + i, 128, 1, MIDDLE_CHAR);
+      do_test (&json_ctx, 32 + i, 1, 2, MIDDLE_CHAR);
+      do_test (&json_ctx, 32 + i, 2, 1, MIDDLE_CHAR);
+    }
+
   for (i = 1; i < 8; ++i)
     {
       do_test (&json_ctx, 0, i, i - 1, MIDDLE_CHAR);
@@ -149,18 +167,49 @@ test_main (void)
     {
       do_test (&json_ctx, 0, 1 << i, 5000, MIDDLE_CHAR);
       do_test (&json_ctx, 1, 1 << i, 5000, MIDDLE_CHAR);
+      do_test (&json_ctx, 0, 5000, 1 << i, MIDDLE_CHAR);
+      do_test (&json_ctx, 1, 5000, 1 << i, MIDDLE_CHAR);
     }
 
   for (i = 1; i < 8; ++i)
-    do_test (&json_ctx, 0, i, 5000, BIG_CHAR);
+    {
+      do_test (&json_ctx, 0, i, 5000, BIG_CHAR);
+      do_test (&json_ctx, 0, 5000, i, BIG_CHAR);
+    }
 
   for (i = 1; i < 8; ++i)
-    do_test (&json_ctx, i, i, 5000, BIG_CHAR);
+    {
+      do_test (&json_ctx, i, i, 5000, BIG_CHAR);
+      do_test (&json_ctx, i, 5000, i, BIG_CHAR);
+    }
 
   for (i = 2; i <= 10; ++i)
     {
       do_test (&json_ctx, 0, 1 << i, 5000, BIG_CHAR);
       do_test (&json_ctx, 1, 1 << i, 5000, BIG_CHAR);
+      do_test (&json_ctx, 0, 5000, 1 << i, BIG_CHAR);
+      do_test (&json_ctx, 1, 5000, 1 << i, BIG_CHAR);
+    }
+
+  for (i = (16 / sizeof (CHAR)); i <= (8192 / sizeof (CHAR)); i += i)
+    {
+      for (j = 0; j <= (704 / sizeof (CHAR)); j += (32 / sizeof (CHAR)))
+	{
+	  do_test (&json_ctx, 0, 1 << i, (i + j), BIG_CHAR);
+	  do_test (&json_ctx, 0, i + j, i, BIG_CHAR);
+
+	  do_test (&json_ctx, 64, 1 << i, (i + j), BIG_CHAR);
+	  do_test (&json_ctx, 64, i + j, i, BIG_CHAR);
+
+	  if (j < i)
+	    {
+	      do_test (&json_ctx, 0, 1 << i, i - j, BIG_CHAR);
+	      do_test (&json_ctx, 0, i - j, i, BIG_CHAR);
+
+	      do_test (&json_ctx, 64, 1 << i, i - j, BIG_CHAR);
+	      do_test (&json_ctx, 64, i - j, i, BIG_CHAR);
+	    }
+	}
     }
 
   json_array_end (&json_ctx);
-- 
2.34.1


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

* Re: [PATCH v1] Benchtest: Add additional benchmarks for strlen and strnlen
  2022-09-28 19:20 [PATCH v1] Benchtest: Add additional benchmarks for strlen and strnlen Noah Goldstein
@ 2022-09-28 19:25 ` H.J. Lu
  2022-09-28 19:26 ` Sunil Pandey
  1 sibling, 0 replies; 4+ messages in thread
From: H.J. Lu @ 2022-09-28 19:25 UTC (permalink / raw)
  To: Noah Goldstein; +Cc: libc-alpha, carlos

On Wed, Sep 28, 2022 at 12:20 PM Noah Goldstein <goldstein.w.n@gmail.com> wrote:
>
> Current benchmarks are missing many cases in the mid-length range
> which is often the hottest size range.
> ---
>  benchtests/bench-strlen.c  | 33 ++++++++++++++++++++---
>  benchtests/bench-strnlen.c | 55 +++++++++++++++++++++++++++++++++++---
>  2 files changed, 81 insertions(+), 7 deletions(-)
>
> diff --git a/benchtests/bench-strlen.c b/benchtests/bench-strlen.c
> index 602e52ee83..696e4541d7 100644
> --- a/benchtests/bench-strlen.c
> +++ b/benchtests/bench-strlen.c
> @@ -128,10 +128,10 @@ test_main (void)
>    /* Checking with only 4 * N alignments for wcslen, other alignments are wrong for wchar_t type arrays*/
>
>    for (i = 1; i < 8; ++i)
> -  {
> -    do_test (&json_ctx, sizeof (CHAR) * i, i);
> -    do_test (&json_ctx, 0, i);
> -  }
> +    {
> +      do_test (&json_ctx, sizeof (CHAR) * i, i);
> +      do_test (&json_ctx, 0, i);
> +    }
>
>    for (i = 2; i <= 12; ++i)
>      {
> @@ -141,6 +141,31 @@ test_main (void)
>        do_test (&json_ctx, sizeof (CHAR) * i, (size_t)((1 << i) / 1.5));
>      }
>
> +  for (i = 0; i < 512; i += 32)
> +    {
> +      do_test (&json_ctx, 0, i / sizeof (CHAR));
> +    }
> +
> +  for (i = 512; i < 1024; i += 64)
> +    {
> +      do_test (&json_ctx, 0, i / sizeof (CHAR));
> +    }
> +
> +  for (i = 1024; i < 2048; i += 128)
> +    {
> +      do_test (&json_ctx, 0, i / sizeof (CHAR));
> +    }
> +
> +  for (i = 2048; i < 4096; i += 256)
> +    {
> +      do_test (&json_ctx, 0, i / sizeof (CHAR));
> +    }
> +
> +  for (i = 4096; i < 8192; i += 512)
> +    {
> +      do_test (&json_ctx, 0, i / sizeof (CHAR));
> +    }
> +
>    json_array_end (&json_ctx);
>    json_attr_object_end (&json_ctx);
>    json_attr_object_end (&json_ctx);
> diff --git a/benchtests/bench-strnlen.c b/benchtests/bench-strnlen.c
> index 2cd561dfd5..13b46b3f57 100644
> --- a/benchtests/bench-strnlen.c
> +++ b/benchtests/bench-strnlen.c
> @@ -63,6 +63,11 @@ do_one_test (json_ctx_t *json_ctx, impl_t *impl, const CHAR *s, size_t maxlen,
>        ret = 1;
>        return;
>      }
> +  /* Warmup.  */
> +  for (i = 0; i < iters / 16; ++i)
> +    {
> +      CALL (impl, s, maxlen);
> +    }
>
>    TIMING_NOW (start);
>    for (i = 0; i < iters; ++i)
> @@ -110,7 +115,7 @@ do_test (json_ctx_t *json_ctx, size_t align, size_t len, size_t maxlen,
>  int
>  test_main (void)
>  {
> -  size_t i;
> +  size_t i, j;
>    json_ctx_t json_ctx;
>
>    test_init ();
> @@ -131,6 +136,19 @@ test_main (void)
>
>    json_array_begin (&json_ctx, "results");
>
> +  for (i = 0; i <= 1; ++i)
> +    {
> +      do_test (&json_ctx, i, 1, 128, MIDDLE_CHAR);
> +      do_test (&json_ctx, i, 128, 1, MIDDLE_CHAR);
> +      do_test (&json_ctx, i, 1, 2, MIDDLE_CHAR);
> +      do_test (&json_ctx, i, 2, 1, MIDDLE_CHAR);
> +
> +      do_test (&json_ctx, 32 + i, 1, 128, MIDDLE_CHAR);
> +      do_test (&json_ctx, 32 + i, 128, 1, MIDDLE_CHAR);
> +      do_test (&json_ctx, 32 + i, 1, 2, MIDDLE_CHAR);
> +      do_test (&json_ctx, 32 + i, 2, 1, MIDDLE_CHAR);
> +    }
> +
>    for (i = 1; i < 8; ++i)
>      {
>        do_test (&json_ctx, 0, i, i - 1, MIDDLE_CHAR);
> @@ -149,18 +167,49 @@ test_main (void)
>      {
>        do_test (&json_ctx, 0, 1 << i, 5000, MIDDLE_CHAR);
>        do_test (&json_ctx, 1, 1 << i, 5000, MIDDLE_CHAR);
> +      do_test (&json_ctx, 0, 5000, 1 << i, MIDDLE_CHAR);
> +      do_test (&json_ctx, 1, 5000, 1 << i, MIDDLE_CHAR);
>      }
>
>    for (i = 1; i < 8; ++i)
> -    do_test (&json_ctx, 0, i, 5000, BIG_CHAR);
> +    {
> +      do_test (&json_ctx, 0, i, 5000, BIG_CHAR);
> +      do_test (&json_ctx, 0, 5000, i, BIG_CHAR);
> +    }
>
>    for (i = 1; i < 8; ++i)
> -    do_test (&json_ctx, i, i, 5000, BIG_CHAR);
> +    {
> +      do_test (&json_ctx, i, i, 5000, BIG_CHAR);
> +      do_test (&json_ctx, i, 5000, i, BIG_CHAR);
> +    }
>
>    for (i = 2; i <= 10; ++i)
>      {
>        do_test (&json_ctx, 0, 1 << i, 5000, BIG_CHAR);
>        do_test (&json_ctx, 1, 1 << i, 5000, BIG_CHAR);
> +      do_test (&json_ctx, 0, 5000, 1 << i, BIG_CHAR);
> +      do_test (&json_ctx, 1, 5000, 1 << i, BIG_CHAR);
> +    }
> +
> +  for (i = (16 / sizeof (CHAR)); i <= (8192 / sizeof (CHAR)); i += i)
> +    {
> +      for (j = 0; j <= (704 / sizeof (CHAR)); j += (32 / sizeof (CHAR)))
> +       {
> +         do_test (&json_ctx, 0, 1 << i, (i + j), BIG_CHAR);
> +         do_test (&json_ctx, 0, i + j, i, BIG_CHAR);
> +
> +         do_test (&json_ctx, 64, 1 << i, (i + j), BIG_CHAR);
> +         do_test (&json_ctx, 64, i + j, i, BIG_CHAR);
> +
> +         if (j < i)
> +           {
> +             do_test (&json_ctx, 0, 1 << i, i - j, BIG_CHAR);
> +             do_test (&json_ctx, 0, i - j, i, BIG_CHAR);
> +
> +             do_test (&json_ctx, 64, 1 << i, i - j, BIG_CHAR);
> +             do_test (&json_ctx, 64, i - j, i, BIG_CHAR);
> +           }
> +       }
>      }
>
>    json_array_end (&json_ctx);
> --
> 2.34.1
>

LGTM.

Thanks.

-- 
H.J.

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

* Re: [PATCH v1] Benchtest: Add additional benchmarks for strlen and strnlen
  2022-09-28 19:20 [PATCH v1] Benchtest: Add additional benchmarks for strlen and strnlen Noah Goldstein
  2022-09-28 19:25 ` H.J. Lu
@ 2022-09-28 19:26 ` Sunil Pandey
  2022-09-28 20:41   ` Noah Goldstein
  1 sibling, 1 reply; 4+ messages in thread
From: Sunil Pandey @ 2022-09-28 19:26 UTC (permalink / raw)
  To: Noah Goldstein; +Cc: GNU C Library

On Wed, Sep 28, 2022 at 12:20 PM Noah Goldstein via Libc-alpha
<libc-alpha@sourceware.org> wrote:
>
> Current benchmarks are missing many cases in the mid-length range
> which is often the hottest size range.

How do you know if the mid-length range is the hottest size range?
Can you please share data to back your claim.

> ---
>  benchtests/bench-strlen.c  | 33 ++++++++++++++++++++---
>  benchtests/bench-strnlen.c | 55 +++++++++++++++++++++++++++++++++++---
>  2 files changed, 81 insertions(+), 7 deletions(-)
>
> diff --git a/benchtests/bench-strlen.c b/benchtests/bench-strlen.c
> index 602e52ee83..696e4541d7 100644
> --- a/benchtests/bench-strlen.c
> +++ b/benchtests/bench-strlen.c
> @@ -128,10 +128,10 @@ test_main (void)
>    /* Checking with only 4 * N alignments for wcslen, other alignments are wrong for wchar_t type arrays*/
>
>    for (i = 1; i < 8; ++i)
> -  {
> -    do_test (&json_ctx, sizeof (CHAR) * i, i);
> -    do_test (&json_ctx, 0, i);
> -  }
> +    {
> +      do_test (&json_ctx, sizeof (CHAR) * i, i);
> +      do_test (&json_ctx, 0, i);
> +    }
>
>    for (i = 2; i <= 12; ++i)
>      {
> @@ -141,6 +141,31 @@ test_main (void)
>        do_test (&json_ctx, sizeof (CHAR) * i, (size_t)((1 << i) / 1.5));
>      }
>
> +  for (i = 0; i < 512; i += 32)
> +    {
> +      do_test (&json_ctx, 0, i / sizeof (CHAR));
> +    }
> +
> +  for (i = 512; i < 1024; i += 64)
> +    {
> +      do_test (&json_ctx, 0, i / sizeof (CHAR));
> +    }
> +
> +  for (i = 1024; i < 2048; i += 128)
> +    {
> +      do_test (&json_ctx, 0, i / sizeof (CHAR));
> +    }
> +
> +  for (i = 2048; i < 4096; i += 256)
> +    {
> +      do_test (&json_ctx, 0, i / sizeof (CHAR));
> +    }
> +
> +  for (i = 4096; i < 8192; i += 512)
> +    {
> +      do_test (&json_ctx, 0, i / sizeof (CHAR));
> +    }
> +
>    json_array_end (&json_ctx);
>    json_attr_object_end (&json_ctx);
>    json_attr_object_end (&json_ctx);
> diff --git a/benchtests/bench-strnlen.c b/benchtests/bench-strnlen.c
> index 2cd561dfd5..13b46b3f57 100644
> --- a/benchtests/bench-strnlen.c
> +++ b/benchtests/bench-strnlen.c
> @@ -63,6 +63,11 @@ do_one_test (json_ctx_t *json_ctx, impl_t *impl, const CHAR *s, size_t maxlen,
>        ret = 1;
>        return;
>      }
> +  /* Warmup.  */
> +  for (i = 0; i < iters / 16; ++i)
> +    {
> +      CALL (impl, s, maxlen);
> +    }
>
>    TIMING_NOW (start);
>    for (i = 0; i < iters; ++i)
> @@ -110,7 +115,7 @@ do_test (json_ctx_t *json_ctx, size_t align, size_t len, size_t maxlen,
>  int
>  test_main (void)
>  {
> -  size_t i;
> +  size_t i, j;
>    json_ctx_t json_ctx;
>
>    test_init ();
> @@ -131,6 +136,19 @@ test_main (void)
>
>    json_array_begin (&json_ctx, "results");
>
> +  for (i = 0; i <= 1; ++i)
> +    {
> +      do_test (&json_ctx, i, 1, 128, MIDDLE_CHAR);
> +      do_test (&json_ctx, i, 128, 1, MIDDLE_CHAR);
> +      do_test (&json_ctx, i, 1, 2, MIDDLE_CHAR);
> +      do_test (&json_ctx, i, 2, 1, MIDDLE_CHAR);
> +
> +      do_test (&json_ctx, 32 + i, 1, 128, MIDDLE_CHAR);
> +      do_test (&json_ctx, 32 + i, 128, 1, MIDDLE_CHAR);
> +      do_test (&json_ctx, 32 + i, 1, 2, MIDDLE_CHAR);
> +      do_test (&json_ctx, 32 + i, 2, 1, MIDDLE_CHAR);
> +    }
> +
>    for (i = 1; i < 8; ++i)
>      {
>        do_test (&json_ctx, 0, i, i - 1, MIDDLE_CHAR);
> @@ -149,18 +167,49 @@ test_main (void)
>      {
>        do_test (&json_ctx, 0, 1 << i, 5000, MIDDLE_CHAR);
>        do_test (&json_ctx, 1, 1 << i, 5000, MIDDLE_CHAR);
> +      do_test (&json_ctx, 0, 5000, 1 << i, MIDDLE_CHAR);
> +      do_test (&json_ctx, 1, 5000, 1 << i, MIDDLE_CHAR);
>      }
>
>    for (i = 1; i < 8; ++i)
> -    do_test (&json_ctx, 0, i, 5000, BIG_CHAR);
> +    {
> +      do_test (&json_ctx, 0, i, 5000, BIG_CHAR);
> +      do_test (&json_ctx, 0, 5000, i, BIG_CHAR);
> +    }
>
>    for (i = 1; i < 8; ++i)
> -    do_test (&json_ctx, i, i, 5000, BIG_CHAR);
> +    {
> +      do_test (&json_ctx, i, i, 5000, BIG_CHAR);
> +      do_test (&json_ctx, i, 5000, i, BIG_CHAR);
> +    }
>
>    for (i = 2; i <= 10; ++i)
>      {
>        do_test (&json_ctx, 0, 1 << i, 5000, BIG_CHAR);
>        do_test (&json_ctx, 1, 1 << i, 5000, BIG_CHAR);
> +      do_test (&json_ctx, 0, 5000, 1 << i, BIG_CHAR);
> +      do_test (&json_ctx, 1, 5000, 1 << i, BIG_CHAR);
> +    }
> +
> +  for (i = (16 / sizeof (CHAR)); i <= (8192 / sizeof (CHAR)); i += i)
> +    {
> +      for (j = 0; j <= (704 / sizeof (CHAR)); j += (32 / sizeof (CHAR)))
> +       {
> +         do_test (&json_ctx, 0, 1 << i, (i + j), BIG_CHAR);
> +         do_test (&json_ctx, 0, i + j, i, BIG_CHAR);
> +
> +         do_test (&json_ctx, 64, 1 << i, (i + j), BIG_CHAR);
> +         do_test (&json_ctx, 64, i + j, i, BIG_CHAR);
> +
> +         if (j < i)
> +           {
> +             do_test (&json_ctx, 0, 1 << i, i - j, BIG_CHAR);
> +             do_test (&json_ctx, 0, i - j, i, BIG_CHAR);
> +
> +             do_test (&json_ctx, 64, 1 << i, i - j, BIG_CHAR);
> +             do_test (&json_ctx, 64, i - j, i, BIG_CHAR);
> +           }
> +       }
>      }
>
>    json_array_end (&json_ctx);
> --
> 2.34.1
>

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

* Re: [PATCH v1] Benchtest: Add additional benchmarks for strlen and strnlen
  2022-09-28 19:26 ` Sunil Pandey
@ 2022-09-28 20:41   ` Noah Goldstein
  0 siblings, 0 replies; 4+ messages in thread
From: Noah Goldstein @ 2022-09-28 20:41 UTC (permalink / raw)
  To: Sunil Pandey; +Cc: GNU C Library

On Wed, Sep 28, 2022 at 12:27 PM Sunil Pandey <skpgkp2@gmail.com> wrote:
>
> On Wed, Sep 28, 2022 at 12:20 PM Noah Goldstein via Libc-alpha
> <libc-alpha@sourceware.org> wrote:
> >
> > Current benchmarks are missing many cases in the mid-length range
> > which is often the hottest size range.
>
> How do you know if the mid-length range is the hottest size range?
> Can you please share data to back your claim.

Its moreso mid/small, just we are missing mid range.
>
> > ---
> >  benchtests/bench-strlen.c  | 33 ++++++++++++++++++++---
> >  benchtests/bench-strnlen.c | 55 +++++++++++++++++++++++++++++++++++---
> >  2 files changed, 81 insertions(+), 7 deletions(-)
> >
> > diff --git a/benchtests/bench-strlen.c b/benchtests/bench-strlen.c
> > index 602e52ee83..696e4541d7 100644
> > --- a/benchtests/bench-strlen.c
> > +++ b/benchtests/bench-strlen.c
> > @@ -128,10 +128,10 @@ test_main (void)
> >    /* Checking with only 4 * N alignments for wcslen, other alignments are wrong for wchar_t type arrays*/
> >
> >    for (i = 1; i < 8; ++i)
> > -  {
> > -    do_test (&json_ctx, sizeof (CHAR) * i, i);
> > -    do_test (&json_ctx, 0, i);
> > -  }
> > +    {
> > +      do_test (&json_ctx, sizeof (CHAR) * i, i);
> > +      do_test (&json_ctx, 0, i);
> > +    }
> >
> >    for (i = 2; i <= 12; ++i)
> >      {
> > @@ -141,6 +141,31 @@ test_main (void)
> >        do_test (&json_ctx, sizeof (CHAR) * i, (size_t)((1 << i) / 1.5));
> >      }
> >
> > +  for (i = 0; i < 512; i += 32)
> > +    {
> > +      do_test (&json_ctx, 0, i / sizeof (CHAR));
> > +    }
> > +
> > +  for (i = 512; i < 1024; i += 64)
> > +    {
> > +      do_test (&json_ctx, 0, i / sizeof (CHAR));
> > +    }
> > +
> > +  for (i = 1024; i < 2048; i += 128)
> > +    {
> > +      do_test (&json_ctx, 0, i / sizeof (CHAR));
> > +    }
> > +
> > +  for (i = 2048; i < 4096; i += 256)
> > +    {
> > +      do_test (&json_ctx, 0, i / sizeof (CHAR));
> > +    }
> > +
> > +  for (i = 4096; i < 8192; i += 512)
> > +    {
> > +      do_test (&json_ctx, 0, i / sizeof (CHAR));
> > +    }
> > +
> >    json_array_end (&json_ctx);
> >    json_attr_object_end (&json_ctx);
> >    json_attr_object_end (&json_ctx);
> > diff --git a/benchtests/bench-strnlen.c b/benchtests/bench-strnlen.c
> > index 2cd561dfd5..13b46b3f57 100644
> > --- a/benchtests/bench-strnlen.c
> > +++ b/benchtests/bench-strnlen.c
> > @@ -63,6 +63,11 @@ do_one_test (json_ctx_t *json_ctx, impl_t *impl, const CHAR *s, size_t maxlen,
> >        ret = 1;
> >        return;
> >      }
> > +  /* Warmup.  */
> > +  for (i = 0; i < iters / 16; ++i)
> > +    {
> > +      CALL (impl, s, maxlen);
> > +    }
> >
> >    TIMING_NOW (start);
> >    for (i = 0; i < iters; ++i)
> > @@ -110,7 +115,7 @@ do_test (json_ctx_t *json_ctx, size_t align, size_t len, size_t maxlen,
> >  int
> >  test_main (void)
> >  {
> > -  size_t i;
> > +  size_t i, j;
> >    json_ctx_t json_ctx;
> >
> >    test_init ();
> > @@ -131,6 +136,19 @@ test_main (void)
> >
> >    json_array_begin (&json_ctx, "results");
> >
> > +  for (i = 0; i <= 1; ++i)
> > +    {
> > +      do_test (&json_ctx, i, 1, 128, MIDDLE_CHAR);
> > +      do_test (&json_ctx, i, 128, 1, MIDDLE_CHAR);
> > +      do_test (&json_ctx, i, 1, 2, MIDDLE_CHAR);
> > +      do_test (&json_ctx, i, 2, 1, MIDDLE_CHAR);
> > +
> > +      do_test (&json_ctx, 32 + i, 1, 128, MIDDLE_CHAR);
> > +      do_test (&json_ctx, 32 + i, 128, 1, MIDDLE_CHAR);
> > +      do_test (&json_ctx, 32 + i, 1, 2, MIDDLE_CHAR);
> > +      do_test (&json_ctx, 32 + i, 2, 1, MIDDLE_CHAR);
> > +    }
> > +
> >    for (i = 1; i < 8; ++i)
> >      {
> >        do_test (&json_ctx, 0, i, i - 1, MIDDLE_CHAR);
> > @@ -149,18 +167,49 @@ test_main (void)
> >      {
> >        do_test (&json_ctx, 0, 1 << i, 5000, MIDDLE_CHAR);
> >        do_test (&json_ctx, 1, 1 << i, 5000, MIDDLE_CHAR);
> > +      do_test (&json_ctx, 0, 5000, 1 << i, MIDDLE_CHAR);
> > +      do_test (&json_ctx, 1, 5000, 1 << i, MIDDLE_CHAR);
> >      }
> >
> >    for (i = 1; i < 8; ++i)
> > -    do_test (&json_ctx, 0, i, 5000, BIG_CHAR);
> > +    {
> > +      do_test (&json_ctx, 0, i, 5000, BIG_CHAR);
> > +      do_test (&json_ctx, 0, 5000, i, BIG_CHAR);
> > +    }
> >
> >    for (i = 1; i < 8; ++i)
> > -    do_test (&json_ctx, i, i, 5000, BIG_CHAR);
> > +    {
> > +      do_test (&json_ctx, i, i, 5000, BIG_CHAR);
> > +      do_test (&json_ctx, i, 5000, i, BIG_CHAR);
> > +    }
> >
> >    for (i = 2; i <= 10; ++i)
> >      {
> >        do_test (&json_ctx, 0, 1 << i, 5000, BIG_CHAR);
> >        do_test (&json_ctx, 1, 1 << i, 5000, BIG_CHAR);
> > +      do_test (&json_ctx, 0, 5000, 1 << i, BIG_CHAR);
> > +      do_test (&json_ctx, 1, 5000, 1 << i, BIG_CHAR);
> > +    }
> > +
> > +  for (i = (16 / sizeof (CHAR)); i <= (8192 / sizeof (CHAR)); i += i)
> > +    {
> > +      for (j = 0; j <= (704 / sizeof (CHAR)); j += (32 / sizeof (CHAR)))
> > +       {
> > +         do_test (&json_ctx, 0, 1 << i, (i + j), BIG_CHAR);
> > +         do_test (&json_ctx, 0, i + j, i, BIG_CHAR);
> > +
> > +         do_test (&json_ctx, 64, 1 << i, (i + j), BIG_CHAR);
> > +         do_test (&json_ctx, 64, i + j, i, BIG_CHAR);
> > +
> > +         if (j < i)
> > +           {
> > +             do_test (&json_ctx, 0, 1 << i, i - j, BIG_CHAR);
> > +             do_test (&json_ctx, 0, i - j, i, BIG_CHAR);
> > +
> > +             do_test (&json_ctx, 64, 1 << i, i - j, BIG_CHAR);
> > +             do_test (&json_ctx, 64, i - j, i, BIG_CHAR);
> > +           }
> > +       }
> >      }
> >
> >    json_array_end (&json_ctx);
> > --
> > 2.34.1
> >

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

end of thread, other threads:[~2022-09-28 20:42 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-28 19:20 [PATCH v1] Benchtest: Add additional benchmarks for strlen and strnlen Noah Goldstein
2022-09-28 19:25 ` H.J. Lu
2022-09-28 19:26 ` Sunil Pandey
2022-09-28 20:41   ` Noah Goldstein

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).