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/>. */
21 # define TEST_NAME "bzero"
24 # define TEST_NAME "memset"
26 # define TEST_NAME "wmemset"
28 #endif /* !TEST_BZERO */
29 #define MIN_PAGE_SIZE 131072
30 #include "bench-string.h"
33 # define SIMPLE_MEMSET simple_memset
35 # define SIMPLE_MEMSET simple_wmemset
40 CHAR
*SIMPLE_MEMSET (CHAR
*, int, size_t);
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)
52 simple_bzero (char *s
, size_t n
)
54 SIMPLE_MEMSET (s
, 0, n
);
58 builtin_bzero (char *s
, size_t n
)
60 __builtin_bzero (s
, n
);
63 typedef CHAR
*(*proto_t
) (CHAR
*, int, size_t);
65 IMPL (SIMPLE_MEMSET
, 0)
67 char *builtin_memset (char *, int, size_t);
68 IMPL (builtin_memset
, 0)
74 builtin_memset (char *s
, int c
, size_t n
)
76 return __builtin_memset (s
, c
, n
);
79 #endif /* !TEST_BZERO */
82 inhibit_loop_to_libcall
83 SIMPLE_MEMSET (CHAR
*s
, int c
, size_t n
)
85 CHAR
*r
= s
, *end
= s
+ n
;
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
;
99 for (i
= 0; i
< iters
; ++i
)
104 CALL (impl
, s
, c
, n
);
105 #endif /* !TEST_BZERO */
109 TIMING_DIFF (cur
, start
, stop
);
111 json_element_double (json_ctx
, (double) cur
/ (double) iters
);
115 do_test (json_ctx_t
*json_ctx
, size_t align
, int c
, size_t len
)
118 if ((align
+ len
) * sizeof (CHAR
) > page_size
)
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
);
133 json_array_end (json_ctx
);
134 json_element_object_end (json_ctx
);
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");
163 for (c
= -65; c
<= 130; c
+= 65)
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
);
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
);
198 #include <support/test-driver.c>