about summary refs log tree commit diff
path: root/benchtests/bench-rawmemchr.c
diff options
context:
space:
mode:
authorNoah Goldstein <goldstein.w.n@gmail.com>2022-10-18 17:44:09 -0700
committerNoah Goldstein <goldstein.w.n@gmail.com>2022-10-19 17:31:03 -0700
commit643a2d01399188192e0da234581034f77c892054 (patch)
tree64d0e00ac4f7a9865a19c416eccdc6639bd371c1 /benchtests/bench-rawmemchr.c
parentb412213eee0afa3b51dfe92b736dfc7c981309f5 (diff)
downloadglibc-643a2d01399188192e0da234581034f77c892054.tar.gz
glibc-643a2d01399188192e0da234581034f77c892054.tar.xz
glibc-643a2d01399188192e0da234581034f77c892054.zip
Bench: Improve benchtests for memchr, strchr, strnlen, strrchr
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)
Diffstat (limited to 'benchtests/bench-rawmemchr.c')
-rw-r--r--benchtests/bench-rawmemchr.c30
1 files changed, 27 insertions, 3 deletions
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);