1 /* Measure memset functions.
2 Copyright (C) 2013-2018 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 MEMSET memset
35 # define SIMPLE_MEMSET simple_memset
36 # define MEMCMP memcmp
39 # define MEMSET wmemset
41 # define SIMPLE_MEMSET simple_wmemset
42 # define MEMCMP wmemcmp
47 CHAR
*SIMPLE_MEMSET (CHAR
*, int, size_t);
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)
59 simple_bzero (char *s
, size_t n
)
61 SIMPLE_MEMSET (s
, 0, n
);
65 builtin_bzero (char *s
, size_t n
)
67 __builtin_bzero (s
, n
);
70 typedef CHAR
*(*proto_t
) (CHAR
*, int, size_t);
72 IMPL (SIMPLE_MEMSET
, 0)
74 char *builtin_memset (char *, int, size_t);
75 IMPL (builtin_memset
, 0)
81 builtin_memset (char *s
, int c
, size_t n
)
83 return __builtin_memset (s
, c
, n
);
86 #endif /* !TEST_BZERO */
89 inhibit_loop_to_libcall
90 SIMPLE_MEMSET (CHAR
*s
, int c
, size_t n
)
92 CHAR
*r
= s
, *end
= s
+ n
;
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
;
106 for (i
= 0; i
< iters
; ++i
)
111 CALL (impl
, s
, c
, n
);
112 #endif /* !TEST_BZERO */
116 TIMING_DIFF (cur
, start
, stop
);
118 json_element_double (json_ctx
, (double) cur
/ (double) iters
);
122 do_test (json_ctx_t
*json_ctx
, size_t align
, int c
, size_t len
)
125 if ((align
+ len
) * sizeof (CHAR
) > page_size
)
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
);
140 json_array_end (json_ctx
);
141 json_element_object_end (json_ctx
);
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");
170 for (c
= -65; c
<= 130; c
+= 65)
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
);
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
);
205 #include <support/test-driver.c>