From patchwork Wed Sep 28 19:20:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Noah Goldstein X-Patchwork-Id: 1684024 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.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=) Authentication-Results: legolas.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=UECYjZ9T; dkim-atps=neutral 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 ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Md5tS5sRpz1ypH for ; Thu, 29 Sep 2022 05:20:32 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 505033857B85 for ; Wed, 28 Sep 2022 19:20:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 505033857B85 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1664392830; bh=tnWCPDik9Gmw+EqNg+g/LVlu+UlTfgzOwz95Np7Yh2Y=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=UECYjZ9TpYYkYfD7jycpt/8dX77KqhOpYQVbsPh4V9dHsH7XMSccr+K6vWgsfQgfl 7B9PqJ03gOZme/0djTugFgl+zqo3ZQZNkfZrSaMkGqJjtMTEM4i1+yE1ODrDiHPZwB sk2MZhEOW984aP2P0wYY8Uf+wyV0WGUSxtQZx8Nk= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qv1-xf2c.google.com (mail-qv1-xf2c.google.com [IPv6:2607:f8b0:4864:20::f2c]) by sourceware.org (Postfix) with ESMTPS id 6DE9B3858016 for ; Wed, 28 Sep 2022 19:20:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6DE9B3858016 Received: by mail-qv1-xf2c.google.com with SMTP id d1so8790189qvs.0 for ; Wed, 28 Sep 2022 12:20:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date; bh=tnWCPDik9Gmw+EqNg+g/LVlu+UlTfgzOwz95Np7Yh2Y=; b=vwH4UbAQq9yBEvGhREid7Z0GrndK5GFutXK+vS2lTIxr9Vp3IJi87XuzPSkbj6oEzz ZkRy8Q9DhQLtW0mSzfYrAqwTpNGiyRNZT2DmNIO37W92EQUF/Q/t8ZVYh4jU18/mL8iA Lc6+ktlTvptfuX2gTY1P/PEvvQbMWDtMUfZ4jmbD2miaHRXoKvQwcOo3em1bGnlx89tJ Dpbtc3A30DDrnvO6JJ/aW/XsvGERLDJDSdYfvMAmyz2tfGde4aOkQ3lanHA4G5aaRI/k BLf2PXV8a/XTyCPqUWh3zS/p28mU91ouv46xS97O6NTvDGeVtc0GXHLFmNpiMXjzwPu9 y7pg== X-Gm-Message-State: ACrzQf22CFC8FABOQ4oIUt3vhaIRX6NE9raSnKjWTTMEi8Tjjpr43epH Q9aGjYznYx4V6U4sB8J8d7MrwtzO/Zg= X-Google-Smtp-Source: AMsMyM7HC45OUo2ifH1w4DvaS05QhoeacBRN+AY7dQMKGtorLlCR7sC9D6NEIwWm7QZ47a3zwkOKaA== X-Received: by 2002:a05:6214:3011:b0:4ad:82d6:d579 with SMTP id ke17-20020a056214301100b004ad82d6d579mr26803599qvb.37.1664392815381; Wed, 28 Sep 2022 12:20:15 -0700 (PDT) Received: from noah-tgl.. (cpe-74-64-106-10.nyc.res.rr.com. [74.64.106.10]) by smtp.gmail.com with ESMTPSA id a19-20020ac84d93000000b00342fc6a8e25sm3481377qtw.50.2022.09.28.12.20.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Sep 2022 12:20:14 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH v1] Benchtest: Add additional benchmarks for strlen and strnlen Date: Wed, 28 Sep 2022 12:20:12 -0700 Message-Id: <20220928192012.2143620-1-goldstein.w.n@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-12.1 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.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" Current benchmarks are missing many cases in the mid-length range which is often the hottest size range. --- benchtests/bench-strlen.c | 33 ++++++++++++++++++++--- benchtests/bench-strnlen.c | 55 +++++++++++++++++++++++++++++++++++--- 2 files changed, 81 insertions(+), 7 deletions(-) diff --git a/benchtests/bench-strlen.c b/benchtests/bench-strlen.c index 602e52ee83..696e4541d7 100644 --- a/benchtests/bench-strlen.c +++ b/benchtests/bench-strlen.c @@ -128,10 +128,10 @@ test_main (void) /* Checking with only 4 * N alignments for wcslen, other alignments are wrong for wchar_t type arrays*/ for (i = 1; i < 8; ++i) - { - do_test (&json_ctx, sizeof (CHAR) * i, i); - do_test (&json_ctx, 0, i); - } + { + do_test (&json_ctx, sizeof (CHAR) * i, i); + do_test (&json_ctx, 0, i); + } for (i = 2; i <= 12; ++i) { @@ -141,6 +141,31 @@ test_main (void) do_test (&json_ctx, sizeof (CHAR) * i, (size_t)((1 << i) / 1.5)); } + for (i = 0; i < 512; i += 32) + { + do_test (&json_ctx, 0, i / sizeof (CHAR)); + } + + for (i = 512; i < 1024; i += 64) + { + do_test (&json_ctx, 0, i / sizeof (CHAR)); + } + + for (i = 1024; i < 2048; i += 128) + { + do_test (&json_ctx, 0, i / sizeof (CHAR)); + } + + for (i = 2048; i < 4096; i += 256) + { + do_test (&json_ctx, 0, i / sizeof (CHAR)); + } + + for (i = 4096; i < 8192; i += 512) + { + do_test (&json_ctx, 0, i / sizeof (CHAR)); + } + json_array_end (&json_ctx); json_attr_object_end (&json_ctx); json_attr_object_end (&json_ctx); 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);