mirror of git://sourceware.org/git/glibc.git
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},)
|
ifeq (${BENCHSET},)
|
||||||
bench-malloc := \
|
bench-malloc := \
|
||||||
|
calloc-simple \
|
||||||
|
calloc-thread \
|
||||||
malloc-simple \
|
malloc-simple \
|
||||||
malloc-thread \
|
malloc-thread \
|
||||||
# bench-malloc
|
# bench-malloc
|
||||||
else
|
else
|
||||||
bench-malloc := $(filter malloc-%,${BENCHSET})
|
bench-malloc := $(filter malloc-%,${BENCHSET})
|
||||||
|
bench-malloc += $(filter calloc-%,${BENCHSET})
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq (${STATIC-BENCHTESTS},yes)
|
ifeq (${STATIC-BENCHTESTS},yes)
|
||||||
|
@ -429,6 +432,8 @@ VALIDBENCHSETNAMES := \
|
||||||
bench-math \
|
bench-math \
|
||||||
bench-pthread \
|
bench-pthread \
|
||||||
bench-string \
|
bench-string \
|
||||||
|
calloc-simple \
|
||||||
|
calloc-thread \
|
||||||
hash-benchset \
|
hash-benchset \
|
||||||
malloc-simple \
|
malloc-simple \
|
||||||
malloc-thread \
|
malloc-thread \
|
||||||
|
@ -469,7 +474,7 @@ bench-set: $(binaries-benchset)
|
||||||
bench-malloc: $(binaries-bench-malloc)
|
bench-malloc: $(binaries-bench-malloc)
|
||||||
for run in $^; do \
|
for run in $^; do \
|
||||||
echo "$${run}"; \
|
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 \
|
for thr in 1 8 16 32; do \
|
||||||
echo "Running $${run} $${thr}"; \
|
echo "Running $${run} $${thr}"; \
|
||||||
$(run-bench) $${thr} > $${run}-$${thr}.out; \
|
$(run-bench) $${thr} > $${run}-$${thr}.out; \
|
||||||
|
|
|
@ -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"
|
|
@ -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
|
License along with the GNU C Library; if not, see
|
||||||
<https://www.gnu.org/licenses/>. */
|
<https://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
|
#ifndef TEST_FUNC
|
||||||
|
# define TEST_FUNC(size) malloc(size)
|
||||||
|
# define TEST_NAME "malloc"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
@ -55,7 +60,7 @@ do_benchmark (malloc_args *args, int **arr)
|
||||||
for (int j = 0; j < iters; j++)
|
for (int j = 0; j < iters; j++)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < n; i++)
|
for (int i = 0; i < n; i++)
|
||||||
arr[i] = malloc (size);
|
arr[i] = TEST_FUNC (size);
|
||||||
|
|
||||||
for (int i = 0; i < n; i++)
|
for (int i = 0; i < n; i++)
|
||||||
free (arr[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, "functions");
|
||||||
|
|
||||||
json_attr_object_begin (&json_ctx, "malloc");
|
json_attr_object_begin (&json_ctx, TEST_NAME);
|
||||||
|
|
||||||
char s[100];
|
char s[100];
|
||||||
double iters2 = iters;
|
double iters2 = iters;
|
||||||
|
|
|
@ -16,6 +16,11 @@
|
||||||
License along with the GNU C Library; if not, see
|
License along with the GNU C Library; if not, see
|
||||||
<https://www.gnu.org/licenses/>. */
|
<https://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
|
#ifndef TEST_FUNC
|
||||||
|
# define TEST_FUNC(size) malloc(size)
|
||||||
|
# define TEST_NAME "malloc"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
@ -137,7 +142,7 @@ malloc_benchmark_loop (void **ptr_arr)
|
||||||
|
|
||||||
free (ptr_arr[next_idx]);
|
free (ptr_arr[next_idx]);
|
||||||
|
|
||||||
ptr_arr[next_idx] = malloc (next_block);
|
ptr_arr[next_idx] = TEST_FUNC (next_block);
|
||||||
|
|
||||||
iters++;
|
iters++;
|
||||||
}
|
}
|
||||||
|
@ -256,7 +261,7 @@ main (int argc, char **argv)
|
||||||
|
|
||||||
json_attr_object_begin (&json_ctx, "functions");
|
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, "");
|
json_attr_object_begin (&json_ctx, "");
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue