From patchwork Tue Jun 7 04:11:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Noah Goldstein X-Patchwork-Id: 1639778 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=pRtU5QXq; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LHH8Y58TPz9s75 for ; Tue, 7 Jun 2022 14:15:41 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 977E4382D52D for ; Tue, 7 Jun 2022 04:15:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 977E4382D52D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1654575339; bh=arY5pmqPrI8nxi7/DJLI3MNCyHkx9QcysnZIm+8FIQg=; 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=pRtU5QXqnYOgGiHe9LtBdBzz9V/iRnkC64+K7Tftwn28DJUxZbv7WIYdtyX6D4Kw5 cvlrGL6pP5bfjN/pFc4o4Ub1qJbZ77K6A4sq6uSJ3DmSfJouQNQ2ns9Qe/K/WXwr42 4eeOh9S6l5JOjae7RUIyC0Sei1zwTwym7ZBSkz/A= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by sourceware.org (Postfix) with ESMTPS id 24671382D445 for ; Tue, 7 Jun 2022 04:11:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 24671382D445 Received: by mail-pj1-x102a.google.com with SMTP id v11-20020a17090a4ecb00b001e2c5b837ccso19670960pjl.3 for ; Mon, 06 Jun 2022 21:11:44 -0700 (PDT) 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=arY5pmqPrI8nxi7/DJLI3MNCyHkx9QcysnZIm+8FIQg=; b=LmzcKYmHZpxCraWf7rMICi57q+9j3lSqzGb1LcJSSD16AMeEy2EBhwsHqx35k/0YBC rDPxRzJCtSByNCha0XRtBkkxReLzo9cUB50b16WIHR9MjzTkX0tt1Xnz+81KdfmhGCnI OrEDsG2NWVPLboiy94S7joVpOFSnkb52ie0OsoaLxcXb66nVq4NH6j1tX3iT7nxliZEF UwTd+eTb5BsEGY3WNfFMH2zGEPRFG/CLi/665PRITV4gzoI4dQgZLEKmAjCeU5Et+yMV /4LdrRrPkaEXMAz5JYH+i0GplDQ4DxVVb2ztxXj7R6CwJI15FAtH4UzKtK4/doMJX1x9 alpQ== X-Gm-Message-State: AOAM532Bw6fSt9/R1C7J5QirhapyjQO+aCtlwJGxLlxA9EKvUwnq0H0c 0dBNu2mn2XT02My1KAgJF2BnCeyiMcQ= X-Google-Smtp-Source: ABdhPJxZEUPduj9emqf3XVb55vrocSITtJlya88+1uV3+UK34sXVe0wEUPCeH7Qd9VUl8oOPjZtmEA== X-Received: by 2002:a17:90a:9481:b0:1e8:7bbf:fa9a with SMTP id s1-20020a17090a948100b001e87bbffa9amr10722311pjo.164.1654575103031; Mon, 06 Jun 2022 21:11:43 -0700 (PDT) Received: from noah-tgl.. ([2600:1010:b04a:6ef:921e:3108:9361:2ef8]) by smtp.gmail.com with ESMTPSA id fv9-20020a17090b0e8900b001e30a16c609sm10689205pjb.21.2022.06.06.21.11.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jun 2022 21:11:42 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH v6 3/8] Benchtests: Improve memrchr benchmarks Date: Mon, 6 Jun 2022 21:11:29 -0700 Message-Id: <20220607041134.2369903-3-goldstein.w.n@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220607041134.2369903-1-goldstein.w.n@gmail.com> References: <20220603044229.2180216-2-goldstein.w.n@gmail.com> <20220607041134.2369903-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, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" Add a second iteration for memrchr to set `pos` starting from the end of the buffer. Previously `pos` was only set relative to the begining of the buffer. This isn't really useful for memrchr because the begining of the search space is (buf + len). Reviewed-by: H.J. Lu --- benchtests/bench-memchr.c | 110 ++++++++++++++++++++++---------------- 1 file changed, 65 insertions(+), 45 deletions(-) diff --git a/benchtests/bench-memchr.c b/benchtests/bench-memchr.c index 4d7212332f..0facda2fa0 100644 --- a/benchtests/bench-memchr.c +++ b/benchtests/bench-memchr.c @@ -76,7 +76,7 @@ do_one_test (json_ctx_t *json_ctx, impl_t *impl, const CHAR *s, int c, static void do_test (json_ctx_t *json_ctx, size_t align, size_t pos, size_t len, - int seek_char) + int seek_char, int invert_pos) { size_t i; @@ -96,7 +96,10 @@ do_test (json_ctx_t *json_ctx, size_t align, size_t pos, size_t len, if (pos < len) { - buf[align + pos] = seek_char; + if (invert_pos) + buf[align + len - pos] = seek_char; + else + buf[align + pos] = seek_char; buf[align + len] = -seek_char; } else @@ -109,6 +112,7 @@ do_test (json_ctx_t *json_ctx, size_t align, size_t pos, size_t len, json_attr_uint (json_ctx, "pos", pos); json_attr_uint (json_ctx, "len", len); json_attr_uint (json_ctx, "seek_char", seek_char); + json_attr_uint (json_ctx, "invert_pos", invert_pos); json_array_begin (json_ctx, "timings"); @@ -123,6 +127,7 @@ int test_main (void) { size_t i; + int repeats; json_ctx_t json_ctx; test_init (); @@ -142,53 +147,68 @@ test_main (void) json_array_begin (&json_ctx, "results"); - for (i = 1; i < 8; ++i) + for (repeats = 0; repeats < 2; ++repeats) { - do_test (&json_ctx, 0, 16 << i, 2048, 23); - do_test (&json_ctx, i, 64, 256, 23); - do_test (&json_ctx, 0, 16 << i, 2048, 0); - do_test (&json_ctx, i, 64, 256, 0); - - do_test (&json_ctx, getpagesize () - 15, 64, 256, 0); + for (i = 1; i < 8; ++i) + { + do_test (&json_ctx, 0, 16 << i, 2048, 23, repeats); + do_test (&json_ctx, i, 64, 256, 23, repeats); + do_test (&json_ctx, 0, 16 << i, 2048, 0, repeats); + do_test (&json_ctx, i, 64, 256, 0, repeats); + + do_test (&json_ctx, getpagesize () - 15, 64, 256, 0, repeats); #ifdef USE_AS_MEMRCHR - /* Also test the position close to the beginning for memrchr. */ - do_test (&json_ctx, 0, i, 256, 23); - do_test (&json_ctx, 0, i, 256, 0); - do_test (&json_ctx, i, i, 256, 23); - do_test (&json_ctx, i, i, 256, 0); + /* Also test the position close to the beginning for memrchr. */ + do_test (&json_ctx, 0, i, 256, 23, repeats); + do_test (&json_ctx, 0, i, 256, 0, repeats); + do_test (&json_ctx, i, i, 256, 23, repeats); + do_test (&json_ctx, i, i, 256, 0, repeats); #endif - } - for (i = 1; i < 8; ++i) - { - do_test (&json_ctx, i, i << 5, 192, 23); - do_test (&json_ctx, i, i << 5, 192, 0); - do_test (&json_ctx, i, i << 5, 256, 23); - do_test (&json_ctx, i, i << 5, 256, 0); - do_test (&json_ctx, i, i << 5, 512, 23); - do_test (&json_ctx, i, i << 5, 512, 0); - - do_test (&json_ctx, getpagesize () - 15, i << 5, 256, 23); - } - for (i = 1; i < 32; ++i) - { - do_test (&json_ctx, 0, i, i + 1, 23); - do_test (&json_ctx, 0, i, i + 1, 0); - do_test (&json_ctx, i, i, i + 1, 23); - do_test (&json_ctx, i, i, i + 1, 0); - do_test (&json_ctx, 0, i, i - 1, 23); - do_test (&json_ctx, 0, i, i - 1, 0); - do_test (&json_ctx, i, i, i - 1, 23); - do_test (&json_ctx, i, i, i - 1, 0); - - do_test (&json_ctx, getpagesize () - 15, i, i - 1, 23); - do_test (&json_ctx, getpagesize () - 15, i, i - 1, 0); - - do_test (&json_ctx, getpagesize () - 15, i, i + 1, 23); - do_test (&json_ctx, getpagesize () - 15, i, i + 1, 0); + } + for (i = 1; i < 8; ++i) + { + do_test (&json_ctx, i, i << 5, 192, 23, repeats); + do_test (&json_ctx, i, i << 5, 192, 0, repeats); + do_test (&json_ctx, i, i << 5, 256, 23, repeats); + do_test (&json_ctx, i, i << 5, 256, 0, repeats); + do_test (&json_ctx, i, i << 5, 512, 23, repeats); + do_test (&json_ctx, i, i << 5, 512, 0, repeats); + + do_test (&json_ctx, getpagesize () - 15, i << 5, 256, 23, repeats); + } + for (i = 1; i < 32; ++i) + { + do_test (&json_ctx, 0, i, i + 1, 23, repeats); + do_test (&json_ctx, 0, i, i + 1, 0, repeats); + do_test (&json_ctx, i, i, i + 1, 23, repeats); + do_test (&json_ctx, i, i, i + 1, 0, repeats); + do_test (&json_ctx, 0, i, i - 1, 23, repeats); + do_test (&json_ctx, 0, i, i - 1, 0, repeats); + do_test (&json_ctx, i, i, i - 1, 23, repeats); + do_test (&json_ctx, i, i, i - 1, 0, repeats); + + do_test (&json_ctx, getpagesize () / 2, i, i + 1, 23, repeats); + do_test (&json_ctx, getpagesize () / 2, i, i + 1, 0, repeats); + do_test (&json_ctx, getpagesize () / 2 + i, i, i + 1, 23, repeats); + do_test (&json_ctx, getpagesize () / 2 + i, i, i + 1, 0, repeats); + do_test (&json_ctx, getpagesize () / 2, i, i - 1, 23, repeats); + do_test (&json_ctx, getpagesize () / 2, i, i - 1, 0, repeats); + do_test (&json_ctx, getpagesize () / 2 + i, i, i - 1, 23, repeats); + do_test (&json_ctx, getpagesize () / 2 + i, i, i - 1, 0, repeats); + + do_test (&json_ctx, getpagesize () - 15, i, i - 1, 23, repeats); + do_test (&json_ctx, getpagesize () - 15, i, i - 1, 0, repeats); + + do_test (&json_ctx, getpagesize () - 15, i, i + 1, 23, repeats); + do_test (&json_ctx, getpagesize () - 15, i, i + 1, 0, repeats); + #ifdef USE_AS_MEMRCHR - /* Also test the position close to the beginning for memrchr. */ - do_test (&json_ctx, 0, 1, i + 1, 23); - do_test (&json_ctx, 0, 2, i + 1, 0); + do_test (&json_ctx, 0, 1, i + 1, 23, repeats); + do_test (&json_ctx, 0, 2, i + 1, 0, repeats); +#endif + } +#ifndef USE_AS_MEMRCHR + break; #endif }