aboutsummaryrefslogtreecommitdiff
path: root/benchtests/bench-strchr.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-strchr.c
parentb412213eee0afa3b51dfe92b736dfc7c981309f5 (diff)
downloadglibc-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-strchr.c')
-rw-r--r--benchtests/bench-strchr.c35
1 files changed, 25 insertions, 10 deletions
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);