manual: Fix the wording to "alternative" rather than "alternate"
[glibc.git] / benchtests / bench-memset.c
blobc2679a6ac108ed267e15947652c064e5c8cd5a2f
1 /* Measure memset functions.
2 Copyright (C) 2013-2019 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 <http://www.gnu.org/licenses/>. */
19 #define TEST_MAIN
20 #ifdef TEST_BZERO
21 # define TEST_NAME "bzero"
22 #else
23 # ifndef WIDE
24 # define TEST_NAME "memset"
25 # else
26 # define TEST_NAME "wmemset"
27 # endif /* WIDE */
28 #endif /* !TEST_BZERO */
29 #define MIN_PAGE_SIZE 131072
30 #include "bench-string.h"
32 #ifndef WIDE
33 # define SIMPLE_MEMSET simple_memset
34 #else
35 # define SIMPLE_MEMSET simple_wmemset
36 #endif /* WIDE */
38 #include "json-lib.h"
40 CHAR *SIMPLE_MEMSET (CHAR *, int, size_t);
42 #ifdef TEST_BZERO
43 typedef void (*proto_t) (char *, size_t);
44 void simple_bzero (char *, size_t);
45 void builtin_bzero (char *, size_t);
47 IMPL (simple_bzero, 0)
48 IMPL (builtin_bzero, 0)
49 IMPL (bzero, 1)
51 void
52 simple_bzero (char *s, size_t n)
54 SIMPLE_MEMSET (s, 0, n);
57 void
58 builtin_bzero (char *s, size_t n)
60 __builtin_bzero (s, n);
62 #else
63 typedef CHAR *(*proto_t) (CHAR *, int, size_t);
65 IMPL (SIMPLE_MEMSET, 0)
66 # ifndef WIDE
67 char *builtin_memset (char *, int, size_t);
68 IMPL (builtin_memset, 0)
69 # endif /* !WIDE */
70 IMPL (MEMSET, 1)
72 # ifndef WIDE
73 char *
74 builtin_memset (char *s, int c, size_t n)
76 return __builtin_memset (s, c, n);
78 # endif /* !WIDE */
79 #endif /* !TEST_BZERO */
81 CHAR *
82 inhibit_loop_to_libcall
83 SIMPLE_MEMSET (CHAR *s, int c, size_t n)
85 CHAR *r = s, *end = s + n;
86 while (r < end)
87 *r++ = c;
88 return s;
91 static void
92 do_one_test (json_ctx_t *json_ctx, impl_t *impl, CHAR *s,
93 int c __attribute ((unused)), size_t n)
95 size_t i, iters = INNER_LOOP_ITERS;
96 timing_t start, stop, cur;
98 TIMING_NOW (start);
99 for (i = 0; i < iters; ++i)
101 #ifdef TEST_BZERO
102 CALL (impl, s, n);
103 #else
104 CALL (impl, s, c, n);
105 #endif /* !TEST_BZERO */
107 TIMING_NOW (stop);
109 TIMING_DIFF (cur, start, stop);
111 json_element_double (json_ctx, (double) cur / (double) iters);
114 static void
115 do_test (json_ctx_t *json_ctx, size_t align, int c, size_t len)
117 align &= 63;
118 if ((align + len) * sizeof (CHAR) > page_size)
119 return;
121 json_element_object_begin (json_ctx);
122 json_attr_uint (json_ctx, "length", len);
123 json_attr_uint (json_ctx, "alignment", align);
124 json_attr_int (json_ctx, "char", c);
125 json_array_begin (json_ctx, "timings");
127 FOR_EACH_IMPL (impl, 0)
129 do_one_test (json_ctx, impl, (CHAR *) (buf1) + align, c, len);
130 alloc_bufs ();
133 json_array_end (json_ctx);
134 json_element_object_end (json_ctx);
138 test_main (void)
140 json_ctx_t json_ctx;
141 size_t i;
142 int c = 0;
144 test_init ();
146 json_init (&json_ctx, 0, stdout);
148 json_document_begin (&json_ctx);
149 json_attr_string (&json_ctx, "timing_type", TIMING_TYPE);
151 json_attr_object_begin (&json_ctx, "functions");
152 json_attr_object_begin (&json_ctx, TEST_NAME);
153 json_attr_string (&json_ctx, "bench-variant", "");
155 json_array_begin (&json_ctx, "ifuncs");
156 FOR_EACH_IMPL (impl, 0)
157 json_element_string (&json_ctx, impl->name);
158 json_array_end (&json_ctx);
160 json_array_begin (&json_ctx, "results");
162 #ifndef TEST_BZERO
163 for (c = -65; c <= 130; c += 65)
164 #endif
166 for (i = 0; i < 18; ++i)
167 do_test (&json_ctx, 0, c, 1 << i);
168 for (i = 1; i < 32; ++i)
170 do_test (&json_ctx, i, c, i);
171 if (i & (i - 1))
172 do_test (&json_ctx, 0, c, i);
174 for (i = 32; i < 512; i+=32)
176 do_test (&json_ctx, 0, c, i);
177 do_test (&json_ctx, i, c, i);
179 do_test (&json_ctx, 1, c, 14);
180 do_test (&json_ctx, 3, c, 1024);
181 do_test (&json_ctx, 4, c, 64);
182 do_test (&json_ctx, 2, c, 25);
184 for (i = 33; i <= 256; i += 4)
186 do_test (&json_ctx, 0, c, 32 * i);
187 do_test (&json_ctx, i, c, 32 * i);
190 json_array_end (&json_ctx);
191 json_attr_object_end (&json_ctx);
192 json_attr_object_end (&json_ctx);
193 json_document_end (&json_ctx);
195 return ret;
198 #include <support/test-driver.c>