From: Wilco Dijkstra <Wilco.Dijkstra@arm.com>
To: 'GNU C Library' <libc-alpha@sourceware.org>
Subject: [PATCH] benchtests: Add difficult strstr needle for bruteforce algorithms
Date: Thu, 18 Apr 2024 13:03:22 +0000 [thread overview]
Message-ID: <PAWPR08MB8982F63E1AF0745763EC682B830E2@PAWPR08MB8982.eurprd08.prod.outlook.com> (raw)
Add another difficult needle to strstr that clearly shows the quadratic
complexity of bruteforce algorithms.
OK for commit?
---
diff --git a/benchtests/bench-strstr.c b/benchtests/bench-strstr.c
index 9288ad16e963d5397419aa11263520d259d2d6b9..4b07d39a50b0e5e1f29743a258b05466099c1959 100644
--- a/benchtests/bench-strstr.c
+++ b/benchtests/bench-strstr.c
@@ -352,6 +352,33 @@ test_hard_needle (json_ctx_t *json_ctx, size_t ne_len, size_t hs_len)
json_array_end (json_ctx);
json_element_object_end (json_ctx);
}
+
+ /* Hard needle for bruteforce algorithms that match first few chars. */
+ {
+ memset (hs, 'a', hs_len);
+ for (int i = ne_len-1; i < hs_len; i += ne_len)
+ hs[i] = 'b';
+ hs[hs_len] = 0;
+
+ memset (ne, 'a', ne_len);
+ ne[ne_len] = 0;
+
+ json_element_object_begin (json_ctx);
+ json_attr_uint (json_ctx, "len_haystack", hs_len);
+ json_attr_uint (json_ctx, "len_needle", ne_len);
+ json_attr_uint (json_ctx, "align_haystack", 0);
+ json_attr_uint (json_ctx, "align_needle", 0);
+ json_attr_uint (json_ctx, "fail", 1);
+ json_attr_string (json_ctx, "desc", "Difficult bruteforce needle");
+
+ json_array_begin (json_ctx, "timings");
+
+ FOR_EACH_IMPL (impl, 0)
+ do_one_test (json_ctx, impl, hs, ne, NULL);
+
+ json_array_end (json_ctx);
+ json_element_object_end (json_ctx);
+ }
}
static int
next reply other threads:[~2024-04-18 13:04 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-18 13:03 Wilco Dijkstra [this message]
2024-04-23 18:47 ` [PATCH] benchtests: Add difficult strstr needle for bruteforce algorithms Adhemerval Zanella Netto
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
List information: https://www.gnu.org/software/libc/involved.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=PAWPR08MB8982F63E1AF0745763EC682B830E2@PAWPR08MB8982.eurprd08.prod.outlook.com \
--to=wilco.dijkstra@arm.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).