diff options
author | Noah Goldstein <goldstein.w.n@gmail.com> | 2022-09-28 12:20:12 -0700 |
---|---|---|
committer | Noah Goldstein <goldstein.w.n@gmail.com> | 2022-09-28 20:16:04 -0700 |
commit | 5eb21c62cea9e5879e7637ac6713ba2cb5993ca5 (patch) | |
tree | 9cda9bc9d0845f914c9cf5d8ca7200a836eda02c /benchtests/bench-strnlen.c | |
parent | b0969fa53a28b4ab2159806bf6c99a98999502ee (diff) | |
download | glibc-5eb21c62cea9e5879e7637ac6713ba2cb5993ca5.tar.gz glibc-5eb21c62cea9e5879e7637ac6713ba2cb5993ca5.tar.xz glibc-5eb21c62cea9e5879e7637ac6713ba2cb5993ca5.zip |
Benchtest: Add additional benchmarks for strlen and strnlen
Current benchmarks are missing many cases in the mid-length range which is often the hottest size range.
Diffstat (limited to 'benchtests/bench-strnlen.c')
-rw-r--r-- | benchtests/bench-strnlen.c | 55 |
1 files changed, 52 insertions, 3 deletions
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); |