From patchwork Wed Apr 24 14:04:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wilco Dijkstra X-Patchwork-Id: 32402 Received: (qmail 17873 invoked by alias); 24 Apr 2019 14:04:16 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 17860 invoked by uid 89); 24 Apr 2019 14:04:16 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-16.4 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS autolearn=ham version=3.3.1 spammy=i5, shows X-HELO: EUR01-DB5-obe.outbound.protection.outlook.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector1-arm-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=8x9aXBITwpgG1WqKE/aQZCmarRL/iwGR8f5NbJOEyzE=; b=bl4gWf3f8CQtqQ0IwxJZF7hK9p9aXQqhuG2OzkP1Vqe/Ne6z3KVpRSYFajJGkxRpKEkkbWBUjj3ukd2SfuqRPnyZqHCvNTiZw9vnGOosi/wy3nz+gASlnCubeqDwva+9AWNbCa9qC8qBfqug65F8n0b4Vx5889WCw2klfWyre0U= From: Wilco Dijkstra To: "libc-alpha@sourceware.org" CC: nd Subject: [PATCH] Benchmark strstr hard needles Date: Wed, 24 Apr 2019 14:04:07 +0000 Message-ID: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Wilco.Dijkstra@arm.com; received-spf: None (protection.outlook.com: arm.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 MIME-Version: 1.0 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED Benchmark hard needles both for Two-way and the new strstr algorithm. This shows how the worst cases are quite close and both much faster than the quadratic basic_strstr. Thanks to Szabolcs for providing various hard needles. ChangeLog: 2019-04-24 Wilco Dijkstra * benchtests/bench-strstr.c (test_hard_needle): New function. diff --git a/benchtests/bench-strstr.c b/benchtests/bench-strstr.c index 31309b24029a96de7381e1050fd89e5d26642e5f..5cb889aa8dbf4a08940159f8ddca717f59deb88d 100644 --- a/benchtests/bench-strstr.c +++ b/benchtests/bench-strstr.c @@ -203,6 +203,52 @@ do_test (size_t align1, size_t align2, size_t len1, size_t len2, putchar ('\n'); } + +char * volatile null = NULL; + +static void +test_hard_needle (size_t ne_len, size_t hs_len) +{ + char *ne = (char *) buf1; + char *hs = (char *) buf2; + + /* Hard needle for strstr algorithm using skip table. */ + memset (ne, 'a', ne_len); + ne[ne_len] = '\0'; + ne[ne_len - 6] = 'b'; + + memset (hs, 'a', hs_len); + for (size_t i = ne_len; i < hs_len; i += ne_len) + { + hs[i-5] = 'b'; + hs[i-6] = 'b'; + } + + printf ("Length %4zd/%3zd, complex needle 1:", hs_len, ne_len); + + FOR_EACH_IMPL (impl, 0) + do_one_test (impl, hs, ne, null); + putchar ('\n'); + + /* Hard needle for Two-way algorithm. */ + for (int i = 0; i < hs_len; i++) + hs[i] = (rand () & 255) > 155 ? 'a' : 'b'; + hs[hs_len] = 0; + + memset (ne, 'a', ne_len); + ne[ne_len-2] = 'b'; + ne[0] = 'b'; + ne[ne_len] = 0; + + printf ("Length %4zd/%3zd, complex needle 2:", hs_len, ne_len); + + { + FOR_EACH_IMPL (impl, 0) + do_one_test (impl, hs, ne, null); + putchar ('\n'); + } +} + static int test_main (void) { @@ -227,6 +273,10 @@ test_main (void) do_test (14, 5, hlen, klen, 1); } + test_hard_needle (64, 65536); + test_hard_needle (255, 65536); + test_hard_needle (1024, 65536); + return ret; }