diff options
author | Wangyang Guo <wangyang.guo@intel.com> | 2024-11-29 16:05:35 +0800 |
---|---|---|
committer | H.J. Lu <hjl.tools@gmail.com> | 2024-11-29 19:04:28 +0800 |
commit | 2d6427a63cad8056ba6bcaaaa8df21977c8dde3d (patch) | |
tree | 0af48fd8aa244a5193202a5ebe59e58a1e0e1f37 | |
parent | 19a198f05802fcc05441c364ed75311ef3f6d663 (diff) | |
download | glibc-2d6427a63cad8056ba6bcaaaa8df21977c8dde3d.zip glibc-2d6427a63cad8056ba6bcaaaa8df21977c8dde3d.tar.gz glibc-2d6427a63cad8056ba6bcaaaa8df21977c8dde3d.tar.bz2 |
benchtests: Add calloc test
Two new benchmarks related to calloc added:
- bench-calloc-simple
- bench-calloc-thread
Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
-rw-r--r-- | benchtests/Makefile | 7 | ||||
-rw-r--r-- | benchtests/bench-calloc-simple.c | 22 | ||||
-rw-r--r-- | benchtests/bench-calloc-thread.c | 22 | ||||
-rw-r--r-- | benchtests/bench-malloc-simple.c | 9 | ||||
-rw-r--r-- | benchtests/bench-malloc-thread.c | 9 |
5 files changed, 64 insertions, 5 deletions
diff --git a/benchtests/Makefile b/benchtests/Makefile index 23db840..2ee5516 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 0000000..61a4b47 --- /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 + <https://www.gnu.org/licenses/>. */ + +#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 0000000..82e3c98 --- /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 + <https://www.gnu.org/licenses/>. */ + +#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 289bb66..2af52ae 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 <https://www.gnu.org/licenses/>. */ +#ifndef TEST_FUNC +# define TEST_FUNC(size) malloc(size) +# define TEST_NAME "malloc" +#endif + #include <pthread.h> #include <stdio.h> #include <stdlib.h> @@ -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 46fdabd..92c4162 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 <https://www.gnu.org/licenses/>. */ +#ifndef TEST_FUNC +# define TEST_FUNC(size) malloc(size) +# define TEST_NAME "malloc" +#endif + #include <errno.h> #include <math.h> #include <pthread.h> @@ -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, ""); |