MIPS: Add relocation types
[glibc.git] / benchtests / bench-bzero.c
blob5e891ce87549d017587df4fc2a4cdaba788b4093
1 /* Measure bzero functions.
2 Copyright (C) 2022-2023 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
19 #define TEST_MAIN
20 #ifdef DO_MEMSET
21 # define TEST_NAME "memset"
22 #else
23 # define TEST_NAME "bzero"
24 #endif
25 #define MIN_PAGE_SIZE 131072
26 #include "bench-string.h"
28 #include "json-lib.h"
30 #ifdef DO_MEMSET
31 void *generic_memset (void *, int, size_t);
33 typedef void *(*proto_t) (void *, int, size_t);
35 IMPL (memset, 1)
36 IMPL (generic_memset, 0)
38 #else
39 static void
40 memset_zero (void * s, size_t len)
42 memset (s, '\0', len);
45 typedef void (*proto_t) (void *, size_t);
47 IMPL (bzero, 1)
48 IMPL (memset_zero, 0)
49 #endif
51 static void
52 do_one_test (json_ctx_t *json_ctx, impl_t *impl, CHAR *s, size_t n)
54 size_t i, iters = INNER_LOOP_ITERS8;
55 timing_t start, stop, cur;
57 TIMING_NOW (start);
58 for (i = 0; i < iters; ++i)
60 #ifdef DO_MEMSET
61 CALL (impl, s, 0, n);
62 #else
63 CALL (impl, s, n);
64 #endif
66 TIMING_NOW (stop);
68 TIMING_DIFF (cur, start, stop);
70 json_element_double (json_ctx, (double) cur / (double) iters);
73 static void
74 do_test (json_ctx_t *json_ctx, size_t align, size_t len)
76 align &= 4095;
77 if ((align + len) * sizeof (CHAR) > page_size)
78 return;
80 json_element_object_begin (json_ctx);
81 json_attr_uint (json_ctx, "length", len);
82 json_attr_uint (json_ctx, "alignment", align);
83 json_array_begin (json_ctx, "timings");
85 FOR_EACH_IMPL (impl, 0)
87 do_one_test (json_ctx, impl, (CHAR *) (buf1) + align, len);
90 json_array_end (json_ctx);
91 json_element_object_end (json_ctx);
94 int
95 test_main (void)
97 json_ctx_t json_ctx;
98 size_t i;
100 test_init ();
101 alloc_bufs ();
102 json_init (&json_ctx, 0, stdout);
104 json_document_begin (&json_ctx);
105 json_attr_string (&json_ctx, "timing_type", TIMING_TYPE);
107 json_attr_object_begin (&json_ctx, "functions");
108 json_attr_object_begin (&json_ctx, TEST_NAME);
109 json_attr_string (&json_ctx, "bench-variant", "default");
111 json_array_begin (&json_ctx, "ifuncs");
112 FOR_EACH_IMPL (impl, 0)
113 json_element_string (&json_ctx, impl->name);
114 json_array_end (&json_ctx);
116 json_array_begin (&json_ctx, "results");
118 for (i = 0; i < 18; ++i)
119 do_test (&json_ctx, 0, 1 << i);
120 for (i = 0; i < 64; ++i)
122 do_test (&json_ctx, i, i);
123 do_test (&json_ctx, 4096 - i, i);
124 do_test (&json_ctx, 4095, i);
125 if (i & (i - 1))
126 do_test (&json_ctx, 0, i);
128 for (i = 32; i < 1024; i+=32)
130 do_test (&json_ctx, 0, i);
131 do_test (&json_ctx, i, i);
133 do_test (&json_ctx, 1, 14);
134 do_test (&json_ctx, 3, 1024);
135 do_test (&json_ctx, 4, 64);
136 do_test (&json_ctx, 2, 25);
138 for (i = 33; i <= 256; i += 4)
140 do_test (&json_ctx, 0, 32 * i);
141 do_test (&json_ctx, i, 32 * i);
144 json_array_end (&json_ctx);
145 json_attr_object_end (&json_ctx);
146 json_attr_object_end (&json_ctx);
147 json_document_end (&json_ctx);
149 return ret;
152 #include <support/test-driver.c>
154 #ifdef DO_MEMSET
155 # define libc_hidden_builtin_def(X)
156 # define libc_hidden_def(X)
157 # define libc_hidden_weak(X)
158 # define weak_alias(X,Y)
159 # undef MEMSET
160 # define MEMSET generic_memset
161 # include <string/memset.c>
162 #endif