public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Noah Goldstein <goldstein.w.n@gmail.com>
To: "H.J. Lu" <hjl.tools@gmail.com>
Cc: libc-alpha@sourceware.org, carlos@systemhalted.org
Subject: Re: [PATCH v2 7/7] Bench: Improve benchtests for memchr, strchr, strnlen, strrchr
Date: Tue, 18 Oct 2022 17:44:33 -0700	[thread overview]
Message-ID: <CAFUsyf+mq=hoaZCkqh240--ED4kfQsx86fzCPnAd8wNWqmF-0Q@mail.gmail.com> (raw)
In-Reply-To: <CAMe9rOpyM14yc_AD=CSv5nugW4FHijOwJMoEozv56Bkfw9yd3Q@mail.gmail.com>

On Tue, Oct 18, 2022 at 5:01 PM H.J. Lu <hjl.tools@gmail.com> wrote:
>
> On Tue, Oct 18, 2022 at 4:19 PM Noah Goldstein <goldstein.w.n@gmail.com> wrote:
> >
> > 1. Add more complete coverage in the medium size range.
> > 2. In strnlen remove the `1 << i` which was UB (`i` could go beyond
> >    32/64)
> > 3. Add timer for total benchmark runtime (useful for deciding about
> >    tradeoff between coverage and runtime).
>
> Please drop #3.

Fixed.
>
> > ---
> >  benchtests/bench-memchr.c    | 77 +++++++++++++++++++++++++-----------
> >  benchtests/bench-rawmemchr.c | 30 ++++++++++++--
> >  benchtests/bench-strchr.c    | 35 +++++++++++-----
> >  benchtests/bench-strnlen.c   | 12 +++---
> >  benchtests/bench-strrchr.c   | 28 ++++++++++++-
> >  5 files changed, 137 insertions(+), 45 deletions(-)
> >
> > diff --git a/benchtests/bench-memchr.c b/benchtests/bench-memchr.c
> > index 0facda2fa0..2ec9dd86d0 100644
> > --- a/benchtests/bench-memchr.c
> > +++ b/benchtests/bench-memchr.c
> > @@ -126,7 +126,7 @@ do_test (json_ctx_t *json_ctx, size_t align, size_t pos, size_t len,
> >  int
> >  test_main (void)
> >  {
> > -  size_t i;
> > +  size_t i, j, al, al_max;
> >    int repeats;
> >    json_ctx_t json_ctx;
> >    test_init ();
> > @@ -147,35 +147,46 @@ test_main (void)
> >
> >    json_array_begin (&json_ctx, "results");
> >
> > +  al_max = 0;
> > +#ifdef USE_AS_MEMRCHR
> > +  al_max = getpagesize () / 2;
> > +#endif
> > +
> >    for (repeats = 0; repeats < 2; ++repeats)
> >      {
> > -      for (i = 1; i < 8; ++i)
> > +      for (al = 0; al <= al_max; al += getpagesize () / 2)
> >         {
> > -         do_test (&json_ctx, 0, 16 << i, 2048, 23, repeats);
> > -         do_test (&json_ctx, i, 64, 256, 23, repeats);
> > -         do_test (&json_ctx, 0, 16 << i, 2048, 0, repeats);
> > -         do_test (&json_ctx, i, 64, 256, 0, repeats);
> > -
> > -         do_test (&json_ctx, getpagesize () - 15, 64, 256, 0, repeats);
> > +         for (i = 1; i < 8; ++i)
> > +           {
> > +             do_test (&json_ctx, al, 16 << i, 2048, 23, repeats);
> > +             do_test (&json_ctx, al + i, 64, 256, 23, repeats);
> > +             do_test (&json_ctx, al, 16 << i, 2048, 0, repeats);
> > +             do_test (&json_ctx, al + i, 64, 256, 0, repeats);
> > +
> > +             do_test (&json_ctx, al + getpagesize () - 15, 64, 256, 0,
> > +                      repeats);
> >  #ifdef USE_AS_MEMRCHR
> > -         /* Also test the position close to the beginning for memrchr.  */
> > -         do_test (&json_ctx, 0, i, 256, 23, repeats);
> > -         do_test (&json_ctx, 0, i, 256, 0, repeats);
> > -         do_test (&json_ctx, i, i, 256, 23, repeats);
> > -         do_test (&json_ctx, i, i, 256, 0, repeats);
> > +             /* Also test the position close to the beginning for memrchr.  */
> > +             do_test (&json_ctx, al, i, 256, 23, repeats);
> > +             do_test (&json_ctx, al, i, 256, 0, repeats);
> > +             do_test (&json_ctx, al + i, i, 256, 23, repeats);
> > +             do_test (&json_ctx, al + i, i, 256, 0, repeats);
> >  #endif
> > +           }
> > +         for (i = 1; i < 8; ++i)
> > +           {
> > +             do_test (&json_ctx, al + i, i << 5, 192, 23, repeats);
> > +             do_test (&json_ctx, al + i, i << 5, 192, 0, repeats);
> > +             do_test (&json_ctx, al + i, i << 5, 256, 23, repeats);
> > +             do_test (&json_ctx, al + i, i << 5, 256, 0, repeats);
> > +             do_test (&json_ctx, al + i, i << 5, 512, 23, repeats);
> > +             do_test (&json_ctx, al + i, i << 5, 512, 0, repeats);
> > +
> > +             do_test (&json_ctx, al + getpagesize () - 15, i << 5, 256, 23,
> > +                      repeats);
> > +           }
> >         }
> > -      for (i = 1; i < 8; ++i)
> > -       {
> > -         do_test (&json_ctx, i, i << 5, 192, 23, repeats);
> > -         do_test (&json_ctx, i, i << 5, 192, 0, repeats);
> > -         do_test (&json_ctx, i, i << 5, 256, 23, repeats);
> > -         do_test (&json_ctx, i, i << 5, 256, 0, repeats);
> > -         do_test (&json_ctx, i, i << 5, 512, 23, repeats);
> > -         do_test (&json_ctx, i, i << 5, 512, 0, repeats);
> > -
> > -         do_test (&json_ctx, getpagesize () - 15, i << 5, 256, 23, repeats);
> > -       }
> > +
> >        for (i = 1; i < 32; ++i)
> >         {
> >           do_test (&json_ctx, 0, i, i + 1, 23, repeats);
> > @@ -207,6 +218,24 @@ test_main (void)
> >           do_test (&json_ctx, 0, 2, i + 1, 0, repeats);
> >  #endif
> >         }
> > +      for (al = 0; al <= al_max; al += getpagesize () / 2)
> > +       {
> > +         for (i = (16 / sizeof (CHAR)); i <= (8192 / sizeof (CHAR)); i += i)
> > +           {
> > +             for (j = 0; j <= (384 / sizeof (CHAR));
> > +                  j += (32 / sizeof (CHAR)))
> > +               {
> > +                 do_test (&json_ctx, al, i + j, i, 23, repeats);
> > +                 do_test (&json_ctx, al, i, i + j, 23, repeats);
> > +                 if (j < i)
> > +                   {
> > +                     do_test (&json_ctx, al, i - j, i, 23, repeats);
> > +                     do_test (&json_ctx, al, i, i - j, 23, repeats);
> > +                   }
> > +               }
> > +           }
> > +       }
> > +
> >  #ifndef USE_AS_MEMRCHR
> >        break;
> >  #endif
> > diff --git a/benchtests/bench-rawmemchr.c b/benchtests/bench-rawmemchr.c
> > index b1803afc14..dab77f3858 100644
> > --- a/benchtests/bench-rawmemchr.c
> > +++ b/benchtests/bench-rawmemchr.c
> > @@ -70,7 +70,7 @@ do_test (json_ctx_t *json_ctx, size_t align, size_t pos, size_t len, int seek_ch
> >    size_t i;
> >    char *result;
> >
> > -  align &= 7;
> > +  align &= getpagesize () - 1;
> >    if (align + len >= page_size)
> >      return;
> >
> > @@ -106,7 +106,6 @@ test_main (void)
> >  {
> >    json_ctx_t json_ctx;
> >    size_t i;
> > -
> >    test_init ();
> >
> >    json_init (&json_ctx, 0, stdout);
> > @@ -120,7 +119,7 @@ test_main (void)
> >
> >    json_array_begin (&json_ctx, "ifuncs");
> >    FOR_EACH_IMPL (impl, 0)
> > -      json_element_string (&json_ctx, impl->name);
> > +    json_element_string (&json_ctx, impl->name);
> >    json_array_end (&json_ctx);
> >
> >    json_array_begin (&json_ctx, "results");
> > @@ -137,6 +136,31 @@ test_main (void)
> >        do_test (&json_ctx, 0, i, i + 1, 23);
> >        do_test (&json_ctx, 0, i, i + 1, 0);
> >      }
> > +  for (; i < 256; i += 32)
> > +    {
> > +      do_test (&json_ctx, 0, i, i + 1, 23);
> > +      do_test (&json_ctx, 0, i - 1, i, 23);
> > +    }
> > +  for (; i < 512; i += 64)
> > +    {
> > +      do_test (&json_ctx, 0, i, i + 1, 23);
> > +      do_test (&json_ctx, 0, i - 1, i, 23);
> > +    }
> > +  for (; i < 1024; i += 128)
> > +    {
> > +      do_test (&json_ctx, 0, i, i + 1, 23);
> > +      do_test (&json_ctx, 0, i - 1, i, 23);
> > +    }
> > +  for (; i < 2048; i += 256)
> > +    {
> > +      do_test (&json_ctx, 0, i, i + 1, 23);
> > +      do_test (&json_ctx, 0, i - 1, i, 23);
> > +    }
> > +  for (; i < 4096; i += 512)
> > +    {
> > +      do_test (&json_ctx, 0, i, i + 1, 23);
> > +      do_test (&json_ctx, 0, i - 1, i, 23);
> > +    }
> >
> >    json_array_end (&json_ctx);
> >    json_attr_object_end (&json_ctx);
> > diff --git a/benchtests/bench-strchr.c b/benchtests/bench-strchr.c
> > index 54640bde7e..aeb882d442 100644
> > --- a/benchtests/bench-strchr.c
> > +++ b/benchtests/bench-strchr.c
> > @@ -287,8 +287,8 @@ int
> >  test_main (void)
> >  {
> >    json_ctx_t json_ctx;
> > -  size_t i;
> >
> > +  size_t i, j;
> >    test_init ();
> >
> >    json_init (&json_ctx, 0, stdout);
> > @@ -367,15 +367,30 @@ test_main (void)
> >        do_test (&json_ctx, 0, i, i + 1, 0, BIG_CHAR);
> >      }
> >
> > -  DO_RAND_TEST(&json_ctx, 0, 15, 16, 0.0);
> > -  DO_RAND_TEST(&json_ctx, 0, 15, 16, 0.1);
> > -  DO_RAND_TEST(&json_ctx, 0, 15, 16, 0.25);
> > -  DO_RAND_TEST(&json_ctx, 0, 15, 16, 0.33);
> > -  DO_RAND_TEST(&json_ctx, 0, 15, 16, 0.5);
> > -  DO_RAND_TEST(&json_ctx, 0, 15, 16, 0.66);
> > -  DO_RAND_TEST(&json_ctx, 0, 15, 16, 0.75);
> > -  DO_RAND_TEST(&json_ctx, 0, 15, 16, 0.9);
> > -  DO_RAND_TEST(&json_ctx, 0, 15, 16, 1.0);
> > +  for (i = 16 / sizeof (CHAR); i <= 8192 / sizeof (CHAR); i += i)
> > +    {
> > +      for (j = 32 / sizeof (CHAR); j <= 320 / sizeof (CHAR);
> > +          j += 32 / sizeof (CHAR))
> > +       {
> > +         do_test (&json_ctx, 0, i, i + j, 0, MIDDLE_CHAR);
> > +         do_test (&json_ctx, 0, i + j, i, 0, MIDDLE_CHAR);
> > +         if (i > j)
> > +           {
> > +             do_test (&json_ctx, 0, i, i - j, 0, MIDDLE_CHAR);
> > +             do_test (&json_ctx, 0, i - j, i, 0, MIDDLE_CHAR);
> > +           }
> > +       }
> > +    }
> > +
> > +  DO_RAND_TEST (&json_ctx, 0, 15, 16, 0.0);
> > +  DO_RAND_TEST (&json_ctx, 0, 15, 16, 0.1);
> > +  DO_RAND_TEST (&json_ctx, 0, 15, 16, 0.25);
> > +  DO_RAND_TEST (&json_ctx, 0, 15, 16, 0.33);
> > +  DO_RAND_TEST (&json_ctx, 0, 15, 16, 0.5);
> > +  DO_RAND_TEST (&json_ctx, 0, 15, 16, 0.66);
> > +  DO_RAND_TEST (&json_ctx, 0, 15, 16, 0.75);
> > +  DO_RAND_TEST (&json_ctx, 0, 15, 16, 0.9);
> > +  DO_RAND_TEST (&json_ctx, 0, 15, 16, 1.0);
> >
> >    json_array_end (&json_ctx);
> >    json_attr_object_end (&json_ctx);
> > diff --git a/benchtests/bench-strnlen.c b/benchtests/bench-strnlen.c
> > index 13b46b3f57..82c02eb6ed 100644
> > --- a/benchtests/bench-strnlen.c
> > +++ b/benchtests/bench-strnlen.c
> > @@ -195,19 +195,19 @@ test_main (void)
> >      {
> >        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);
> >
> > +         do_test (&json_ctx, 0, i, i + j, BIG_CHAR);
> > +         do_test (&json_ctx, 64, i, i + j, 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);
> > +
> > +             do_test (&json_ctx, 0, i, i - j, BIG_CHAR);
> > +             do_test (&json_ctx, 64, i, i - j, BIG_CHAR);
> >             }
> >         }
> >      }
> > diff --git a/benchtests/bench-strrchr.c b/benchtests/bench-strrchr.c
> > index 7cd2a15484..3fcf3f281d 100644
> > --- a/benchtests/bench-strrchr.c
> > +++ b/benchtests/bench-strrchr.c
> > @@ -151,7 +151,7 @@ int
> >  test_main (void)
> >  {
> >    json_ctx_t json_ctx;
> > -  size_t i, j;
> > +  size_t i, j, k;
> >    int seek;
> >
> >    test_init ();
> > @@ -173,7 +173,7 @@ test_main (void)
> >
> >    for (seek = 0; seek <= 23; seek += 23)
> >      {
> > -      for (j = 1; j < 32; j += j)
> > +      for (j = 1; j <= 256; j = (j * 4))
> >         {
> >           for (i = 1; i < 9; ++i)
> >             {
> > @@ -197,6 +197,30 @@ test_main (void)
> >               do_test (&json_ctx, getpagesize () - i / 2 - 1, i, i + 1, seek,
> >                        SMALL_CHAR, j);
> >             }
> > +
> > +         for (i = (16 / sizeof (CHAR)); i <= (288 / sizeof (CHAR)); i += 32)
> > +           {
> > +             do_test (&json_ctx, 0, i - 16, i, seek, SMALL_CHAR, j);
> > +             do_test (&json_ctx, 0, i, i + 16, seek, SMALL_CHAR, j);
> > +           }
> > +
> > +         for (i = (16 / sizeof (CHAR)); i <= (2048 / sizeof (CHAR)); i += i)
> > +           {
> > +             for (k = 0; k <= (288 / sizeof (CHAR));
> > +                  k += (48 / sizeof (CHAR)))
> > +               {
> > +                 do_test (&json_ctx, 0, k, i, seek, SMALL_CHAR, j);
> > +                 do_test (&json_ctx, 0, i, i + k, seek, SMALL_CHAR, j);
> > +
> > +                 if (k < i)
> > +                   {
> > +                     do_test (&json_ctx, 0, i - k, i, seek, SMALL_CHAR, j);
> > +                     do_test (&json_ctx, 0, k, i - k, seek, SMALL_CHAR, j);
> > +                     do_test (&json_ctx, 0, i, i - k, seek, SMALL_CHAR, j);
> > +                   }
> > +               }
> > +           }
> > +
> >           if (seek == 0)
> >             {
> >               break;
> > --
> > 2.34.1
> >
>
>
> --
> H.J.

  reply	other threads:[~2022-10-19  0:44 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-18  2:48 [PATCH v1 1/7] x86: Optimize memchr-evex.S and implement with VMM headers Noah Goldstein
2022-10-18  2:48 ` [PATCH v1 2/7] x86: Shrink / minorly optimize strchr-evex " Noah Goldstein
2022-10-18  2:51   ` Noah Goldstein
2022-10-18  2:48 ` [PATCH v1 3/7] x86: Optimize strnlen-evex.S " Noah Goldstein
2022-10-18  2:51   ` Noah Goldstein
2022-10-18  2:48 ` [PATCH v1 4/7] x86: Optimize memrchr-evex.S Noah Goldstein
2022-10-18  2:51   ` Noah Goldstein
2022-10-18  2:48 ` [PATCH v1 5/7] x86: Optimize strrchr-evex.S and implement with VMM headers Noah Goldstein
2022-10-18  2:52   ` Noah Goldstein
2022-10-18  2:49 ` [PATCH v1 6/7] x86: Add support for VEC_SIZE == 64 in strcmp-evex.S impl Noah Goldstein
2022-10-20  2:15   ` [PATCH v4] " Noah Goldstein
2022-10-20  3:46     ` H.J. Lu
2022-10-18  2:49 ` [PATCH v1 7/7] Bench: Improve benchtests for memchr, strchr, strnlen, strrchr Noah Goldstein
2022-10-18 21:00   ` H.J. Lu
2022-10-18 21:05     ` Noah Goldstein
2022-10-18 21:53       ` H.J. Lu
2022-10-18 22:58         ` Noah Goldstein
2022-10-18  2:50 ` [PATCH v1 1/7] x86: Optimize memchr-evex.S and implement with VMM headers Noah Goldstein
2022-10-18 23:19 ` [PATCH v2 " Noah Goldstein
2022-10-18 23:19   ` [PATCH v2 2/7] x86: Shrink / minorly optimize strchr-evex " Noah Goldstein
2022-10-18 23:19   ` [PATCH v2 3/7] x86: Optimize strnlen-evex.S " Noah Goldstein
2022-10-18 23:19   ` [PATCH v2 4/7] x86: Optimize memrchr-evex.S Noah Goldstein
2022-10-18 23:19   ` [PATCH v2 5/7] x86: Optimize strrchr-evex.S and implement with VMM headers Noah Goldstein
2022-10-18 23:19   ` [PATCH v2 6/7] x86: Add support for VEC_SIZE == 64 in strcmp-evex.S impl Noah Goldstein
2022-10-18 23:19   ` [PATCH v2 7/7] Bench: Improve benchtests for memchr, strchr, strnlen, strrchr Noah Goldstein
2022-10-19  0:01     ` H.J. Lu
2022-10-19  0:44       ` Noah Goldstein [this message]
2022-10-19  0:44 ` [PATCH v3 1/7] x86: Optimize memchr-evex.S and implement with VMM headers Noah Goldstein
2022-10-19  0:44   ` [PATCH v3 2/7] x86: Shrink / minorly optimize strchr-evex " Noah Goldstein
2022-10-19 16:53     ` H.J. Lu
2022-10-19  0:44   ` [PATCH v3 3/7] x86: Optimize strnlen-evex.S " Noah Goldstein
2022-10-19 16:57     ` H.J. Lu
2022-10-19  0:44   ` [PATCH v3 4/7] x86: Optimize memrchr-evex.S Noah Goldstein
2022-10-19 16:58     ` H.J. Lu
2022-10-19  0:44   ` [PATCH v3 5/7] x86: Optimize strrchr-evex.S and implement with VMM headers Noah Goldstein
2022-10-19 16:58     ` H.J. Lu
2022-10-19  0:44   ` [PATCH v3 6/7] x86: Add support for VEC_SIZE == 64 in strcmp-evex.S impl Noah Goldstein
2022-10-19 16:59     ` H.J. Lu
2022-10-19  0:44   ` [PATCH v3 7/7] Bench: Improve benchtests for memchr, strchr, strnlen, strrchr Noah Goldstein
2022-10-19 17:00     ` H.J. Lu
2022-10-19 16:52   ` [PATCH v3 1/7] x86: Optimize memchr-evex.S and implement with VMM headers H.J. Lu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAFUsyf+mq=hoaZCkqh240--ED4kfQsx86fzCPnAd8wNWqmF-0Q@mail.gmail.com' \
    --to=goldstein.w.n@gmail.com \
    --cc=carlos@systemhalted.org \
    --cc=hjl.tools@gmail.com \
    --cc=libc-alpha@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).