From: Wangyang Guo Date: Fri, 29 Nov 2024 08:05:35 +0000 (+0800) Subject: benchtests: Add calloc test X-Git-Tag: glibc-2.41~432 X-Git-Url: https://sourceware.org/git/?a=commitdiff_plain;h=2d6427a63cad8056ba6bcaaaa8df21977c8dde3d;p=glibc.git benchtests: Add calloc test Two new benchmarks related to calloc added: - bench-calloc-simple - bench-calloc-thread Reviewed-by: H.J. Lu --- diff --git a/benchtests/Makefile b/benchtests/Makefile index 23db840666..2ee5516d55 100644 --- a/benchtests/Makefile +++ b/benchtests/Makefile @@ -308,11 +308,14 @@ CFLAGS-bench-isfinite.c += $(config-cflags-signaling-nans) ifeq (${BENCHSET},) bench-malloc := \ + calloc-simple \ + calloc-thread \ malloc-simple \ malloc-thread \ # bench-malloc else bench-malloc := $(filter malloc-%,${BENCHSET}) +bench-malloc += $(filter calloc-%,${BENCHSET}) endif ifeq (${STATIC-BENCHTESTS},yes) @@ -429,6 +432,8 @@ VALIDBENCHSETNAMES := \ bench-math \ bench-pthread \ bench-string \ + calloc-simple \ + calloc-thread \ hash-benchset \ malloc-simple \ malloc-thread \ @@ -469,7 +474,7 @@ bench-set: $(binaries-benchset) bench-malloc: $(binaries-bench-malloc) for run in $^; do \ echo "$${run}"; \ - if [ `basename $${run}` = "bench-malloc-thread" ]; then \ + if [[ `basename $${run}` =~ bench-[cm]alloc-thread ]]; then \ for thr in 1 8 16 32; do \ echo "Running $${run} $${thr}"; \ $(run-bench) $${thr} > $${run}-$${thr}.out; \ diff --git a/benchtests/bench-calloc-simple.c b/benchtests/bench-calloc-simple.c new file mode 100644 index 0000000000..61a4b474c9 --- /dev/null +++ b/benchtests/bench-calloc-simple.c @@ -0,0 +1,22 @@ +/* Benchmark calloc and free functions. + Copyright (C) 2024 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#define TEST_FUNC(size) calloc (1, size) +#define TEST_NAME "calloc" + +#include "bench-malloc-simple.c" diff --git a/benchtests/bench-calloc-thread.c b/benchtests/bench-calloc-thread.c new file mode 100644 index 0000000000..82e3c989a1 --- /dev/null +++ b/benchtests/bench-calloc-thread.c @@ -0,0 +1,22 @@ +/* Benchmark calloc and free functions. + Copyright (C) 2024 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#define TEST_FUNC(size) calloc (1, size) +#define TEST_NAME "calloc" + +#include "bench-malloc-thread.c" diff --git a/benchtests/bench-malloc-simple.c b/benchtests/bench-malloc-simple.c index 289bb660ad..2af52ae6b8 100644 --- a/benchtests/bench-malloc-simple.c +++ b/benchtests/bench-malloc-simple.c @@ -16,6 +16,11 @@ License along with the GNU C Library; if not, see . */ +#ifndef TEST_FUNC +# define TEST_FUNC(size) malloc(size) +# define TEST_NAME "malloc" +#endif + #include #include #include @@ -55,7 +60,7 @@ do_benchmark (malloc_args *args, int **arr) for (int j = 0; j < iters; j++) { for (int i = 0; i < n; i++) - arr[i] = malloc (size); + arr[i] = TEST_FUNC (size); for (int i = 0; i < n; i++) free (arr[i]); @@ -124,7 +129,7 @@ bench (unsigned long size) json_attr_object_begin (&json_ctx, "functions"); - json_attr_object_begin (&json_ctx, "malloc"); + json_attr_object_begin (&json_ctx, TEST_NAME); char s[100]; double iters2 = iters; diff --git a/benchtests/bench-malloc-thread.c b/benchtests/bench-malloc-thread.c index 46fdabd30c..92c41624ea 100644 --- a/benchtests/bench-malloc-thread.c +++ b/benchtests/bench-malloc-thread.c @@ -16,6 +16,11 @@ License along with the GNU C Library; if not, see . */ +#ifndef TEST_FUNC +# define TEST_FUNC(size) malloc(size) +# define TEST_NAME "malloc" +#endif + #include #include #include @@ -137,7 +142,7 @@ malloc_benchmark_loop (void **ptr_arr) free (ptr_arr[next_idx]); - ptr_arr[next_idx] = malloc (next_block); + ptr_arr[next_idx] = TEST_FUNC (next_block); iters++; } @@ -256,7 +261,7 @@ main (int argc, char **argv) json_attr_object_begin (&json_ctx, "functions"); - json_attr_object_begin (&json_ctx, "malloc"); + json_attr_object_begin (&json_ctx, TEST_NAME); json_attr_object_begin (&json_ctx, "");