From patchwork Tue Mar 6 13:41:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siddhesh Poyarekar X-Patchwork-Id: 26209 Received: (qmail 50751 invoked by alias); 6 Mar 2018 13:41:54 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 50631 invoked by uid 89); 6 Mar 2018 13:41:54 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_NEUTRAL autolearn=ham version=3.3.2 spammy= X-HELO: homiemail-a56.g.dreamhost.com From: Siddhesh Poyarekar To: libc-alpha@sourceware.org Subject: [COMMITTED 2/3] benchtests: Reallocate buffers for every strncmp implementation Date: Tue, 6 Mar 2018 19:11:37 +0530 Message-Id: <20180306134138.27724-2-siddhesh@sourceware.org> In-Reply-To: <20180306134138.27724-1-siddhesh@sourceware.org> References: <20180306134138.27724-1-siddhesh@sourceware.org> Don't reuse buffers for different strncmp implementations since the earlier implementation will end up warming the cache for the later one. Eventually there should be a more elegant way to do this. * benchtests/bench-strncmp.c (do_test_limit): Reallocate buffers for every implementation. (do_test): Likewise. --- benchtests/bench-strncmp.c | 97 +++++++++++++++++++++++++--------------------- 1 file changed, 53 insertions(+), 44 deletions(-) diff --git a/benchtests/bench-strncmp.c b/benchtests/bench-strncmp.c index 713a07210d..4354d708fb 100644 --- a/benchtests/bench-strncmp.c +++ b/benchtests/bench-strncmp.c @@ -139,8 +139,6 @@ do_test_limit (json_ctx_t *json_ctx, size_t align1, size_t align2, size_t len, if (n == 0) { - s1 = (CHAR *) (buf1 + page_size); - s2 = (CHAR *) (buf2 + page_size); json_element_object_begin (json_ctx); json_attr_uint (json_ctx, "strlen", (double) len); json_attr_uint (json_ctx, "len", (double) n); @@ -149,7 +147,12 @@ do_test_limit (json_ctx_t *json_ctx, size_t align1, size_t align2, size_t len, json_array_begin (json_ctx, "timings"); FOR_EACH_IMPL (impl, 0) - do_one_test (json_ctx, impl, s1, s2, n, 0); + { + realloc_bufs (); + s1 = (CHAR *) (buf1 + page_size); + s2 = (CHAR *) (buf2 + page_size); + do_one_test (json_ctx, impl, s1, s2, n, 0); + } json_array_end (json_ctx); json_element_object_end (json_ctx); @@ -161,28 +164,6 @@ do_test_limit (json_ctx_t *json_ctx, size_t align1, size_t align2, size_t len, align2 &= 15; align_n = (page_size - n * CHARBYTES) & 15; - s1 = (CHAR *) (buf1 + page_size - n * CHARBYTES); - s2 = (CHAR *) (buf2 + page_size - n * CHARBYTES); - - if (align1 < align_n) - s1 = (CHAR *) ((char *) s1 - (align_n - align1)); - - if (align2 < align_n) - s2 = (CHAR *) ((char *) s2 - (align_n - align2)); - - for (i = 0; i < n; i++) - s1[i] = s2[i] = 1 + 23 * i % max_char; - - if (len < n) - { - s1[len] = 0; - s2[len] = 0; - if (exp_result < 0) - s2[len] = 32; - else if (exp_result > 0) - s1[len] = 64; - } - json_element_object_begin (json_ctx); json_attr_uint (json_ctx, "strlen", (double) len); json_attr_uint (json_ctx, "len", (double) n); @@ -191,7 +172,32 @@ do_test_limit (json_ctx_t *json_ctx, size_t align1, size_t align2, size_t len, json_array_begin (json_ctx, "timings"); FOR_EACH_IMPL (impl, 0) - do_one_test (json_ctx, impl, s1, s2, n, exp_result); + { + realloc_bufs (); + s1 = (CHAR *) (buf1 + page_size - n * CHARBYTES); + s2 = (CHAR *) (buf2 + page_size - n * CHARBYTES); + + if (align1 < align_n) + s1 = (CHAR *) ((char *) s1 - (align_n - align1)); + + if (align2 < align_n) + s2 = (CHAR *) ((char *) s2 - (align_n - align2)); + + for (i = 0; i < n; i++) + s1[i] = s2[i] = 1 + 23 * i % max_char; + + if (len < n) + { + s1[len] = 0; + s2[len] = 0; + if (exp_result < 0) + s2[len] = 32; + else if (exp_result > 0) + s1[len] = 64; + } + + do_one_test (json_ctx, impl, s1, s2, n, exp_result); + } json_array_end (json_ctx); json_element_object_end (json_ctx); @@ -215,23 +221,6 @@ do_test (json_ctx_t *json_ctx, size_t align1, size_t align2, size_t len, size_t if (align2 + (n + 1) * CHARBYTES >= page_size) return; - 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; - json_element_object_begin (json_ctx); json_attr_uint (json_ctx, "strlen", (double) len); json_attr_uint (json_ctx, "len", (double) n); @@ -240,7 +229,27 @@ do_test (json_ctx_t *json_ctx, size_t align1, size_t align2, size_t len, size_t json_array_begin (json_ctx, "timings"); FOR_EACH_IMPL (impl, 0) - do_one_test (json_ctx, impl, s1, s2, n, exp_result); + { + realloc_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); + } json_array_end (json_ctx); json_element_object_end (json_ctx);