From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qk1-x729.google.com (mail-qk1-x729.google.com [IPv6:2607:f8b0:4864:20::729]) by sourceware.org (Postfix) with ESMTPS id E18AD3858418 for ; Wed, 28 Sep 2022 19:26:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E18AD3858418 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-qk1-x729.google.com with SMTP id s9so8513765qkg.4 for ; Wed, 28 Sep 2022 12:26:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date; bh=LTp3Dwb8BkLwvk5GG3yVf93//kDg0R+2qMtDqfxvARI=; b=aZS52ezsq4WhFk8PXdyYP7GuLT4oqFfrMt0d3UTITc/CdEVrB/jPEenAQTHs7NDeY0 X8sfPnmmp/lj9r8/4M9lRhjNEfSj3V9h0A67P0H46z+fHr14478xvfADnk4fOZAtoLgh Pi/vy5jyTrH4eVmonXvX38WcHVa6D5H7bPJ3R0wN1xSkp2FTCAk07onhYTidzgmNwIQ4 WhTQ8BdGNc/dGtsWEBNwtRrfNAyUv3QzsnfsqS1aFhzISZ+aFjsNzyMiAtBWTdk6KJOi 87BNJ1wsDKYIRkPcJG4Q9/30Ai8A+nCYqKzrV15vG7XSz4ldHTeErZdPkhLLYyHkr3a+ x27g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date; bh=LTp3Dwb8BkLwvk5GG3yVf93//kDg0R+2qMtDqfxvARI=; b=GyMmf6i7IsFrCVFPjZ/zJCzt/3f25flEfFyg7K1k319EPzY7XPKDyYlOqPg0VhC5Ot 3iuhsZbyQTmqCEH7zxQtrwzSEKRG6kboCrlFc64vRFioxZ6GDU6k026/YX2IBs16FYoV QxQ5pEMCPqK/kb2opaMVDyRvRoKV5IKIrOA70cPFIp881+hHw5eIDbhlUmPgkbNTNilS lHNbSIkjbeZN4w0/lMnunykm7IhpCvbMFuC2X8pFbkSOt2s5CeQ+4ytjNOGZH1BJshNe AgIr/tVxzz/QMJNX3e/qB02vtPnm8Sj6WfD9XLGv3/rbpCqoPIrwxy49CZOCRUq7lNFN +OuQ== X-Gm-Message-State: ACrzQf28h5DPmmK3WfTITzJ7Z0bwLpSAPjDlSySqKFfzA5IcfhtEXyaL RsmrCeDdgyXKSXyX9jQn41IupQWYg/8ArgnSdACyhnhK X-Google-Smtp-Source: AMsMyM6sDb5mRxvxZOr6BRn3gcdHWOSBvCFu3Fe0x/kKuUBNjrVY2thRMOSbJ3osXx8uDogXoivB0Uuomx01JY4Uggo= X-Received: by 2002:a05:620a:2552:b0:6ca:bf8f:4d27 with SMTP id s18-20020a05620a255200b006cabf8f4d27mr22262545qko.383.1664393181172; Wed, 28 Sep 2022 12:26:21 -0700 (PDT) MIME-Version: 1.0 References: <20220928192012.2143620-1-goldstein.w.n@gmail.com> In-Reply-To: <20220928192012.2143620-1-goldstein.w.n@gmail.com> From: "H.J. Lu" Date: Wed, 28 Sep 2022 12:25:45 -0700 Message-ID: Subject: Re: [PATCH v1] Benchtest: Add additional benchmarks for strlen and strnlen To: Noah Goldstein Cc: libc-alpha@sourceware.org, carlos@systemhalted.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-3024.5 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: On Wed, Sep 28, 2022 at 12:20 PM Noah Goldstein wrote: > > 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 > LGTM. Thanks. -- H.J.