mirror of
git://sourceware.org/git/glibc.git
synced 2025-03-07 13:28:05 +08:00
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>
This commit is contained in:
parent
19a198f058
commit
2d6427a63c
@ -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; \
|
||||
|
22
benchtests/bench-calloc-simple.c
Normal file
22
benchtests/bench-calloc-simple.c
Normal file
@ -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"
|
22
benchtests/bench-calloc-thread.c
Normal file
22
benchtests/bench-calloc-thread.c
Normal file
@ -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"
|
@ -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;
|
||||
|
@ -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, "");
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user