Remove "[Add new features here]" for 2.27
[glibc.git] / benchtests / bench-memset.c
blob6b5c57f0070832d67b2a3bd3203bdad5d049f797
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 CHAR *SIMPLE_MEMSET (CHAR *, int, size_t);
47 #ifdef TEST_BZERO
48 typedef void (*proto_t) (char *, size_t);
49 void simple_bzero (char *, size_t);
50 void builtin_bzero (char *, size_t);
52 IMPL (simple_bzero, 0)
53 IMPL (builtin_bzero, 0)
54 IMPL (bzero, 1)
56 void
57 simple_bzero (char *s, size_t n)
59 SIMPLE_MEMSET (s, 0, n);
62 void
63 builtin_bzero (char *s, size_t n)
65 __builtin_bzero (s, n);
67 #else
68 typedef CHAR *(*proto_t) (CHAR *, int, size_t);
70 IMPL (SIMPLE_MEMSET, 0)
71 # ifndef WIDE
72 char *builtin_memset (char *, int, size_t);
73 IMPL (builtin_memset, 0)
74 # endif /* !WIDE */
75 IMPL (MEMSET, 1)
77 # ifndef WIDE
78 char *
79 builtin_memset (char *s, int c, size_t n)
81 return __builtin_memset (s, c, n);
83 # endif /* !WIDE */
84 #endif /* !TEST_BZERO */
86 CHAR *
87 inhibit_loop_to_libcall
88 SIMPLE_MEMSET (CHAR *s, int c, size_t n)
90 CHAR *r = s, *end = s + n;
91 while (r < end)
92 *r++ = c;
93 return s;
96 static void
97 do_one_test (impl_t *impl, CHAR *s, int c __attribute ((unused)), size_t n)
99 size_t i, iters = INNER_LOOP_ITERS;
100 timing_t start, stop, cur;
102 TIMING_NOW (start);
103 for (i = 0; i < iters; ++i)
105 #ifdef TEST_BZERO
106 CALL (impl, s, n);
107 #else
108 CALL (impl, s, c, n);
109 #endif /* !TEST_BZERO */
111 TIMING_NOW (stop);
113 TIMING_DIFF (cur, start, stop);
115 TIMING_PRINT_MEAN ((double) cur, (double) iters);
118 static void
119 do_test (size_t align, int c, size_t len)
121 align &= 63;
122 if ((align + len) * sizeof (CHAR) > page_size)
123 return;
125 printf ("Length %4zd, alignment %2zd, c %2d:", len, align, c);
127 FOR_EACH_IMPL (impl, 0)
128 do_one_test (impl, (CHAR *) (buf1) + align, c, len);
130 putchar ('\n');
134 test_main (void)
136 size_t i;
137 int c = 0;
139 test_init ();
141 printf ("%24s", "");
142 FOR_EACH_IMPL (impl, 0)
143 printf ("\t%s", impl->name);
144 putchar ('\n');
146 #ifndef TEST_BZERO
147 for (c = -65; c <= 130; c += 65)
148 #endif
150 for (i = 0; i < 18; ++i)
151 do_test (0, c, 1 << i);
152 for (i = 1; i < 32; ++i)
154 do_test (i, c, i);
155 if (i & (i - 1))
156 do_test (0, c, i);
158 for (i = 32; i < 512; i+=32)
160 do_test (0, c, i);
161 do_test (i, c, i);
163 do_test (1, c, 14);
164 do_test (3, c, 1024);
165 do_test (4, c, 64);
166 do_test (2, c, 25);
168 for (i = 33; i <= 256; i += 4)
170 do_test (0, c, 32 * i);
171 do_test (i, c, 32 * i);
174 return ret;
177 #include <support/test-driver.c>