From patchwork Mon Jan 10 00:27:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Noah Goldstein X-Patchwork-Id: 49778 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 98C5C3857C4B for ; Mon, 10 Jan 2022 00:31:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 98C5C3857C4B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1641774672; bh=bY2VZ0Y5BMIhyq+ySmKAWBqkWf2JOc4fO3B1Z6wOFUU=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=g7F1+WULBAc1AIojyPDSI5bIeLjOB2WwT3EonAfcdXDcHAqMfOmf42a09dpfcqTA4 W5ZK538uTRf4InlZXU2Rl5lxhyqkQLzR/EvHWczUV48pVFnCg3Dt2pb+QpgUT0VT0W ZXDgdmry+yLPCcNuSX18G1kqQkkazsv8ERm1b11M= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) by sourceware.org (Postfix) with ESMTPS id 4AB523891C03 for ; Mon, 10 Jan 2022 00:28:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4AB523891C03 Received: by mail-pl1-x62e.google.com with SMTP id t18so1047050plg.9 for ; Sun, 09 Jan 2022 16:28:02 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=bY2VZ0Y5BMIhyq+ySmKAWBqkWf2JOc4fO3B1Z6wOFUU=; b=f1SegoUHwvvesF32qQeqgeBm4HkpT5mLVTlFnTvDc3+4mqLVenr/kO23ZRxbLgqhh/ nJsoqNEihygamDMHj1wH6GZTbJe9Pwep+68NEiYzUCyrrQmDIsC/GHBS3HOPFun0Gr5+ 3ssUpdWkoGLchQef/LCHJD/pWc7SPdpJeryoMijRsnagUe2LWAUxSHoIgMV+UzLNid0c 7yWgklBUXYkCRCXPenSAdqW+cYhL75pz7Fmpf6KKPBquZQGfME8eafwbYrYjPQGPYbpa LXmerlHsQs0Ri8wus2TPAJCb8YNsJLO99biqQPpBk8KeBNjzp06J0mBjfgTLYeWW8Q/W PRaw== X-Gm-Message-State: AOAM530cK5fgCAXHhi0oGQ0TkbzRjaHsLZJ3vNI6LqbuLJpVkL9AzZmT G5VpBqBhB7pqmrzUCqfxoyhC1Ko42q4= X-Google-Smtp-Source: ABdhPJwQKJ+QWUDIPi0RJo7rl5vYh4QGTLDeqY7Rp/YyQnZVuXMNAhou4z2KZoPzq3r54uRaQcKPoQ== X-Received: by 2002:a17:902:6bc1:b0:149:7c61:ad31 with SMTP id m1-20020a1709026bc100b001497c61ad31mr61863357plt.93.1641774481208; Sun, 09 Jan 2022 16:28:01 -0800 (PST) Received: from localhost.localdomain (c-73-202-60-99.hsd1.ca.comcast.net. [73.202.60.99]) by smtp.googlemail.com with ESMTPSA id x12sm507257pjq.52.2022.01.09.16.28.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Jan 2022 16:28:01 -0800 (PST) To: libc-alpha@sourceware.org Subject: [PATCH v2 7/7] benchtests: Add more coverage for strcmp and strncmp benchmarks Date: Sun, 9 Jan 2022 18:27:46 -0600 Message-Id: <20220110002746.3653516-7-goldstein.w.n@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220110002746.3653516-1-goldstein.w.n@gmail.com> References: <20220109122946.2754917-1-goldstein.w.n@gmail.com> <20220110002746.3653516-1-goldstein.w.n@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Noah Goldstein via Libc-alpha From: Noah Goldstein Reply-To: Noah Goldstein Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" Add more small and medium sized tests for strcmp and strncmp. As well for strcmp add option for more direct control of alignment. Previously alignment was being pushed to the end of the page. While this is the most difficult case to implement, it is far from the common case and so shouldn't be the only benchmark. Signed-off-by: Noah Goldstein --- benchtests/bench-strcmp.c | 142 ++++++++++++++++++++++++++----------- benchtests/bench-strncmp.c | 110 ++++++++++++++++++++-------- 2 files changed, 183 insertions(+), 69 deletions(-) diff --git a/benchtests/bench-strcmp.c b/benchtests/bench-strcmp.c index 387e76fcfb..3a60edfb15 100644 --- a/benchtests/bench-strcmp.c +++ b/benchtests/bench-strcmp.c @@ -99,8 +99,8 @@ do_one_test (json_ctx_t *json_ctx, impl_t *impl, } static void -do_test (json_ctx_t *json_ctx, size_t align1, size_t align2, size_t len, int - max_char, int exp_result) +do_test (json_ctx_t *json_ctx, size_t align1, size_t align2, size_t len, + int max_char, int exp_result, int at_end) { size_t i; @@ -109,19 +109,28 @@ do_test (json_ctx_t *json_ctx, size_t align1, size_t align2, size_t len, int if (len == 0) return; - align1 &= 63; + align1 &= ~(CHARBYTES - 1); + align2 &= ~(CHARBYTES - 1); + + align1 &= (getpagesize () - 1); if (align1 + (len + 1) * CHARBYTES >= page_size) return; - align2 &= 63; + align2 &= (getpagesize () - 1); if (align2 + (len + 1) * CHARBYTES >= page_size) return; /* Put them close to the end of page. */ - i = align1 + CHARBYTES * (len + 2); - s1 = (CHAR *) (buf1 + ((page_size - i) / 16 * 16) + align1); - i = align2 + CHARBYTES * (len + 2); - s2 = (CHAR *) (buf2 + ((page_size - i) / 16 * 16) + align2); + if (at_end) + { + i = align1 + CHARBYTES * (len + 2); + align1 = ((page_size - i) / 16 * 16) + align1; + i = align2 + CHARBYTES * (len + 2); + align2 = ((page_size - i) / 16 * 16) + align2; + } + + s1 = (CHAR *)(buf1 + align1); + s2 = (CHAR *)(buf2 + align2); for (i = 0; i < len; i++) s1[i] = s2[i] = 1 + (23 << ((CHARBYTES - 1) * 8)) * i % max_char; @@ -132,9 +141,9 @@ do_test (json_ctx_t *json_ctx, size_t align1, size_t align2, size_t len, int s2[len - 1] -= exp_result; json_element_object_begin (json_ctx); - json_attr_uint (json_ctx, "length", (double) len); - json_attr_uint (json_ctx, "align1", (double) align1); - json_attr_uint (json_ctx, "align2", (double) align2); + json_attr_uint (json_ctx, "length", (double)len); + json_attr_uint (json_ctx, "align1", (double)align1); + json_attr_uint (json_ctx, "align2", (double)align2); json_array_begin (json_ctx, "timings"); FOR_EACH_IMPL (impl, 0) @@ -202,7 +211,8 @@ int test_main (void) { json_ctx_t json_ctx; - size_t i; + size_t i, j, k; + size_t pg_sz = getpagesize (); test_init (); @@ -221,36 +231,88 @@ test_main (void) json_array_end (&json_ctx); json_array_begin (&json_ctx, "results"); - - for (i = 1; i < 32; ++i) - { - do_test (&json_ctx, CHARBYTES * i, CHARBYTES * i, i, MIDCHAR, 0); - do_test (&json_ctx, CHARBYTES * i, CHARBYTES * i, i, MIDCHAR, 1); - do_test (&json_ctx, CHARBYTES * i, CHARBYTES * i, i, MIDCHAR, -1); - } - - for (i = 1; i < 10 + CHARBYTESLOG; ++i) + for (k = 0; k < 2; ++k) { - do_test (&json_ctx, 0, 0, 2 << i, MIDCHAR, 0); - do_test (&json_ctx, 0, 0, 2 << i, LARGECHAR, 0); - do_test (&json_ctx, 0, 0, 2 << i, MIDCHAR, 1); - do_test (&json_ctx, 0, 0, 2 << i, LARGECHAR, 1); - do_test (&json_ctx, 0, 0, 2 << i, MIDCHAR, -1); - do_test (&json_ctx, 0, 0, 2 << i, LARGECHAR, -1); - do_test (&json_ctx, 0, CHARBYTES * i, 2 << i, MIDCHAR, 1); - do_test (&json_ctx, CHARBYTES * i, CHARBYTES * (i + 1), 2 << i, LARGECHAR, 1); + for (i = 1; i < 32; ++i) + { + do_test (&json_ctx, CHARBYTES * i, CHARBYTES * i, i, MIDCHAR, 0, k); + do_test (&json_ctx, CHARBYTES * i, CHARBYTES * i, i, MIDCHAR, 1, k); + do_test (&json_ctx, CHARBYTES * i, CHARBYTES * i, i, MIDCHAR, -1, k); + } + + for (i = 1; i <= 8192;) + { + /* No page crosses. */ + do_test (&json_ctx, 0, 0, i, MIDCHAR, 0, k); + do_test (&json_ctx, i * CHARBYTES, 0, i, MIDCHAR, 0, k); + do_test (&json_ctx, 0, i * CHARBYTES, i, MIDCHAR, 0, k); + + /* False page crosses. */ + do_test (&json_ctx, pg_sz / 2, pg_sz / 2 - CHARBYTES, i, MIDCHAR, 0, + k); + do_test (&json_ctx, pg_sz / 2 - CHARBYTES, pg_sz / 2, i, MIDCHAR, 0, + k); + + do_test (&json_ctx, pg_sz - (i * CHARBYTES), 0, i, MIDCHAR, 0, k); + do_test (&json_ctx, 0, pg_sz - (i * CHARBYTES), i, MIDCHAR, 0, k); + + /* Real page cross. */ + for (j = 16; j < 128; j += 16) + { + do_test (&json_ctx, pg_sz - j, 0, i, MIDCHAR, 0, k); + do_test (&json_ctx, 0, pg_sz - j, i, MIDCHAR, 0, k); + + do_test (&json_ctx, pg_sz - j, pg_sz - j / 2, i, MIDCHAR, 0, k); + do_test (&json_ctx, pg_sz - j / 2, pg_sz - j, i, MIDCHAR, 0, k); + } + + if (i < 32) + { + ++i; + } + else if (i < 160) + { + i += 8; + } + else if (i < 512) + { + i += 32; + } + else + { + i *= 2; + } + } + + for (i = 1; i < 10 + CHARBYTESLOG; ++i) + { + do_test (&json_ctx, 0, 0, 2 << i, MIDCHAR, 0, k); + do_test (&json_ctx, 0, 0, 2 << i, LARGECHAR, 0, k); + do_test (&json_ctx, 0, 0, 2 << i, MIDCHAR, 1, k); + do_test (&json_ctx, 0, 0, 2 << i, LARGECHAR, 1, k); + do_test (&json_ctx, 0, 0, 2 << i, MIDCHAR, -1, k); + do_test (&json_ctx, 0, 0, 2 << i, LARGECHAR, -1, k); + do_test (&json_ctx, 0, CHARBYTES * i, 2 << i, MIDCHAR, 1, k); + do_test (&json_ctx, CHARBYTES * i, CHARBYTES * (i + 1), 2 << i, + LARGECHAR, 1, k); + } + + for (i = 1; i < 8; ++i) + { + do_test (&json_ctx, CHARBYTES * i, 2 * CHARBYTES * i, 8 << i, + MIDCHAR, 0, k); + do_test (&json_ctx, 2 * CHARBYTES * i, CHARBYTES * i, 8 << i, + LARGECHAR, 0, k); + do_test (&json_ctx, CHARBYTES * i, 2 * CHARBYTES * i, 8 << i, + MIDCHAR, 1, k); + do_test (&json_ctx, 2 * CHARBYTES * i, CHARBYTES * i, 8 << i, + LARGECHAR, 1, k); + do_test (&json_ctx, CHARBYTES * i, 2 * CHARBYTES * i, 8 << i, + MIDCHAR, -1, k); + do_test (&json_ctx, 2 * CHARBYTES * i, CHARBYTES * i, 8 << i, + LARGECHAR, -1, k); + } } - - for (i = 1; i < 8; ++i) - { - do_test (&json_ctx, CHARBYTES * i, 2 * CHARBYTES * i, 8 << i, MIDCHAR, 0); - do_test (&json_ctx, 2 * CHARBYTES * i, CHARBYTES * i, 8 << i, LARGECHAR, 0); - do_test (&json_ctx, CHARBYTES * i, 2 * CHARBYTES * i, 8 << i, MIDCHAR, 1); - do_test (&json_ctx, 2 * CHARBYTES * i, CHARBYTES * i, 8 << i, LARGECHAR, 1); - do_test (&json_ctx, CHARBYTES * i, 2 * CHARBYTES * i, 8 << i, MIDCHAR, -1); - do_test (&json_ctx, 2 * CHARBYTES * i, CHARBYTES * i, 8 << i, LARGECHAR, -1); - } - do_test_page_boundary (&json_ctx); json_array_end (&json_ctx); diff --git a/benchtests/bench-strncmp.c b/benchtests/bench-strncmp.c index b7a01fde64..6673a53521 100644 --- a/benchtests/bench-strncmp.c +++ b/benchtests/bench-strncmp.c @@ -150,43 +150,43 @@ do_test (json_ctx_t *json_ctx, size_t align1, size_t align2, size_t len, size_t if (n == 0) return; - align1 &= 63; + align1 &= getpagesize () - 1; if (align1 + (n + 1) * CHARBYTES >= page_size) return; - align2 &= 7; + align2 &= getpagesize () - 1; if (align2 + (n + 1) * CHARBYTES >= page_size) return; json_element_object_begin (json_ctx); - json_attr_uint (json_ctx, "strlen", (double) len); - json_attr_uint (json_ctx, "len", (double) n); - json_attr_uint (json_ctx, "align1", (double) align1); - json_attr_uint (json_ctx, "align2", (double) align2); + json_attr_uint (json_ctx, "strlen", (double)len); + json_attr_uint (json_ctx, "len", (double)n); + json_attr_uint (json_ctx, "align1", (double)align1); + json_attr_uint (json_ctx, "align2", (double)align2); json_array_begin (json_ctx, "timings"); FOR_EACH_IMPL (impl, 0) - { - alloc_bufs (); - s1 = (CHAR *) (buf1 + align1); - s2 = (CHAR *) (buf2 + align2); - - for (i = 0; i < n; i++) - s1[i] = s2[i] = 1 + (23 << ((CHARBYTES - 1) * 8)) * i % max_char; - - s1[n] = 24 + exp_result; - s2[n] = 23; - s1[len] = 0; - s2[len] = 0; - if (exp_result < 0) - s2[len] = 32; - else if (exp_result > 0) - s1[len] = 64; - if (len >= n) - s2[n - 1] -= exp_result; + { + alloc_bufs (); + s1 = (CHAR *)(buf1 + align1); + s2 = (CHAR *)(buf2 + align2); + + for (i = 0; i < n; i++) + s1[i] = s2[i] = 1 + (23 << ((CHARBYTES - 1) * 8)) * i % max_char; + + s1[n] = 24 + exp_result; + s2[n] = 23; + s1[len] = 0; + s2[len] = 0; + if (exp_result < 0) + s2[len] = 32; + else if (exp_result > 0) + s1[len] = 64; + if (len >= n) + s2[n - 1] -= exp_result; - do_one_test (json_ctx, impl, s1, s2, n, exp_result); - } + do_one_test (json_ctx, impl, s1, s2, n, exp_result); + } json_array_end (json_ctx); json_element_object_end (json_ctx); @@ -319,7 +319,8 @@ int test_main (void) { json_ctx_t json_ctx; - size_t i; + size_t i, j, len; + size_t pg_sz = getpagesize (); test_init (); @@ -334,12 +335,12 @@ 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"); - for (i =0; i < 16; ++i) + for (i = 0; i < 16; ++i) { do_test (&json_ctx, 0, 0, 8, i, 127, 0); do_test (&json_ctx, 0, 0, 8, i, 127, -1); @@ -361,6 +362,57 @@ test_main (void) do_test (&json_ctx, i, 3 * i, 8, i, 255, -1); } + for (len = 0; len <= 128; len += 64) + { + for (i = 1; i <= 8192;) + { + /* No page crosses. */ + do_test (&json_ctx, 0, 0, i, i + len, 127, 0); + do_test (&json_ctx, i * CHARBYTES, 0, i, i + len, 127, 0); + do_test (&json_ctx, 0, i * CHARBYTES, i, i + len, 127, 0); + + /* False page crosses. */ + do_test (&json_ctx, pg_sz / 2, pg_sz / 2 - CHARBYTES, i, i + len, + 127, 0); + do_test (&json_ctx, pg_sz / 2 - CHARBYTES, pg_sz / 2, i, i + len, + 127, 0); + + do_test (&json_ctx, pg_sz - (i * CHARBYTES), 0, i, i + len, 127, + 0); + do_test (&json_ctx, 0, pg_sz - (i * CHARBYTES), i, i + len, 127, + 0); + + /* Real page cross. */ + for (j = 16; j < 128; j += 16) + { + do_test (&json_ctx, pg_sz - j, 0, i, i + len, 127, 0); + do_test (&json_ctx, 0, pg_sz - j, i, i + len, 127, 0); + + do_test (&json_ctx, pg_sz - j, pg_sz - j / 2, i, i + len, + 127, 0); + do_test (&json_ctx, pg_sz - j / 2, pg_sz - j, i, i + len, + 127, 0); + } + + if (i < 32) + { + ++i; + } + else if (i < 160) + { + i += 8; + } + else if (i < 256) + { + i += 32; + } + else + { + i *= 2; + } + } + } + for (i = 1; i < 8; ++i) { do_test (&json_ctx, 0, 0, 8 << i, 16 << i, 127, 0);