locale: Allow "" int_curr_Symbol (bug 22294)
[glibc.git] / benchtests / bench-memset.c
blob724c1059357a0b3f52da8626dfa108ee417b9245
1 /* Measure memset functions.
2 Copyright (C) 2013-2017 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 MEMSET memset
34 # define CHAR char
35 # define SIMPLE_MEMSET simple_memset
36 # define MEMCMP memcmp
37 #else
38 # include <wchar.h>
39 # define MEMSET wmemset
40 # define CHAR wchar_t
41 # define SIMPLE_MEMSET simple_wmemset
42 # define MEMCMP wmemcmp
43 #endif /* WIDE */
45 #include "json-lib.h"
47 CHAR *SIMPLE_MEMSET (CHAR *, int, size_t);
49 #ifdef TEST_BZERO
50 typedef void (*proto_t) (char *, size_t);
51 void simple_bzero (char *, size_t);
52 void builtin_bzero (char *, size_t);
54 IMPL (simple_bzero, 0)
55 IMPL (builtin_bzero, 0)
56 IMPL (bzero, 1)
58 void
59 simple_bzero (char *s, size_t n)
61 SIMPLE_MEMSET (s, 0, n);
64 void
65 builtin_bzero (char *s, size_t n)
67 __builtin_bzero (s, n);
69 #else
70 typedef CHAR *(*proto_t) (CHAR *, int, size_t);
72 IMPL (SIMPLE_MEMSET, 0)
73 # ifndef WIDE
74 char *builtin_memset (char *, int, size_t);
75 IMPL (builtin_memset, 0)
76 # endif /* !WIDE */
77 IMPL (MEMSET, 1)
79 # ifndef WIDE
80 char *
81 builtin_memset (char *s, int c, size_t n)
83 return __builtin_memset (s, c, n);
85 # endif /* !WIDE */
86 #endif /* !TEST_BZERO */
88 CHAR *
89 inhibit_loop_to_libcall
90 SIMPLE_MEMSET (CHAR *s, int c, size_t n)
92 CHAR *r = s, *end = s + n;
93 while (r < end)
94 *r++ = c;
95 return s;
98 static void
99 do_one_test (json_ctx_t *json_ctx, impl_t *impl, CHAR *s,
100 int c __attribute ((unused)), size_t n)
102 size_t i, iters = INNER_LOOP_ITERS;
103 timing_t start, stop, cur;
105 TIMING_NOW (start);
106 for (i = 0; i < iters; ++i)
108 #ifdef TEST_BZERO
109 CALL (impl, s, n);
110 #else
111 CALL (impl, s, c, n);
112 #endif /* !TEST_BZERO */
114 TIMING_NOW (stop);
116 TIMING_DIFF (cur, start, stop);
118 json_element_double (json_ctx, (double) cur / (double) iters);
121 static void
122 do_test (json_ctx_t *json_ctx, size_t align, int c, size_t len)
124 align &= 63;
125 if ((align + len) * sizeof (CHAR) > page_size)
126 return;
128 json_element_object_begin (json_ctx);
129 json_attr_uint (json_ctx, "length", len);
130 json_attr_uint (json_ctx, "alignment", align);
131 json_attr_int (json_ctx, "char", c);
132 json_array_begin (json_ctx, "timings");
134 FOR_EACH_IMPL (impl, 0)
136 do_one_test (json_ctx, impl, (CHAR *) (buf1) + align, c, len);
137 realloc_bufs ();
140 json_array_end (json_ctx);
141 json_element_object_end (json_ctx);
145 test_main (void)
147 json_ctx_t json_ctx;
148 size_t i;
149 int c = 0;
151 test_init ();
153 json_init (&json_ctx, 0, stdout);
155 json_document_begin (&json_ctx);
156 json_attr_string (&json_ctx, "timing_type", TIMING_TYPE);
158 json_attr_object_begin (&json_ctx, "functions");
159 json_attr_object_begin (&json_ctx, TEST_NAME);
160 json_attr_string (&json_ctx, "bench-variant", "");
162 json_array_begin (&json_ctx, "ifuncs");
163 FOR_EACH_IMPL (impl, 0)
164 json_element_string (&json_ctx, impl->name);
165 json_array_end (&json_ctx);
167 json_array_begin (&json_ctx, "results");
169 #ifndef TEST_BZERO
170 for (c = -65; c <= 130; c += 65)
171 #endif
173 for (i = 0; i < 18; ++i)
174 do_test (&json_ctx, 0, c, 1 << i);
175 for (i = 1; i < 32; ++i)
177 do_test (&json_ctx, i, c, i);
178 if (i & (i - 1))
179 do_test (&json_ctx, 0, c, i);
181 for (i = 32; i < 512; i+=32)
183 do_test (&json_ctx, 0, c, i);
184 do_test (&json_ctx, i, c, i);
186 do_test (&json_ctx, 1, c, 14);
187 do_test (&json_ctx, 3, c, 1024);
188 do_test (&json_ctx, 4, c, 64);
189 do_test (&json_ctx, 2, c, 25);
191 for (i = 33; i <= 256; i += 4)
193 do_test (&json_ctx, 0, c, 32 * i);
194 do_test (&json_ctx, i, c, 32 * i);
197 json_array_end (&json_ctx);
198 json_attr_object_end (&json_ctx);
199 json_attr_object_end (&json_ctx);
200 json_document_end (&json_ctx);
202 return ret;
205 #include <support/test-driver.c>