From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-qv1-xf2c.google.com with SMTP id d1so8790189qvs.0 for ; Wed, 28 Sep 2022 12:20:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date; bh=tnWCPDik9Gmw+EqNg+g/LVlu+UlTfgzOwz95Np7Yh2Y=; b=RjfHAYAv3MRA9DV0lNWvZNZFSYvUUZExhT11BZu43m5u6pAhj29dOxgJXx7BpDxPkf ITcPxQJjZ7nA3emiLqp/KBg4czUC+00jLImHeFPiK87dbtQw2QWOlH+GMFTWjNsf4hjK LWeVxCuKfL3CxZ+4VT2QkxFdgu6IOGC1SkK5M0AoliZeBQS5wpvqNAYQ9AuT54nDpiLp qpsFrecj6/2gkG35RzYkHyKDpTIyFf4nqB4c4HUoXaeHuMgm1Hluv0fwCpVFjVgeGbU3 JcuTMb5iMY2xftxUSkcukHQYE39NDNc07TuOnKLKrf5rPLqgKr00IFYi0o4PEqfyoHPb CjxQ== 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) From: Noah Goldstein To: libc-alpha@sourceware.org Cc: goldstein.w.n@gmail.com, hjl.tools@gmail.com, carlos@systemhalted.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 Content-Transfer-Encoding: 8bit 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 List-Id: 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); -- 2.34.1