1 /* Measure memset functions.
2 Copyright (C) 2013-2021 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 <https://www.gnu.org/licenses/>. */
21 # define TEST_NAME "memset"
23 # define TEST_NAME "wmemset"
24 # define generic_memset generic_wmemset
26 #define MIN_PAGE_SIZE 131072
27 #include "bench-string.h"
32 CHAR *generic_wmemset (CHAR *, CHAR, size_t);
34 void *generic_memset (void *, int, size_t);
37 typedef void *(*proto_t) (void *, int, size_t);
40 IMPL (generic_memset, 0)
43 do_one_test (json_ctx_t *json_ctx, impl_t *impl, CHAR *s,
44 int c __attribute ((unused)), size_t n)
46 size_t i, iters = INNER_LOOP_ITERS;
47 timing_t start, stop, cur;
50 for (i = 0; i < iters; ++i)
56 TIMING_DIFF (cur, start, stop);
58 json_element_double (json_ctx, (double) cur / (double) iters);
62 do_test (json_ctx_t *json_ctx, size_t align, int c, size_t len)
65 if ((align + len) * sizeof (CHAR) > page_size)
68 json_element_object_begin (json_ctx);
69 json_attr_uint (json_ctx, "length", len);
70 json_attr_uint (json_ctx, "alignment", align);
71 json_attr_int (json_ctx, "char", c);
72 json_array_begin (json_ctx, "timings");
74 FOR_EACH_IMPL (impl, 0)
76 do_one_test (json_ctx, impl, (CHAR *) (buf1) + align, c, len);
80 json_array_end (json_ctx);
81 json_element_object_end (json_ctx);
93 json_init (&json_ctx, 0, stdout);
95 json_document_begin (&json_ctx);
96 json_attr_string (&json_ctx, "timing_type", TIMING_TYPE);
98 json_attr_object_begin (&json_ctx, "functions");
99 json_attr_object_begin (&json_ctx, TEST_NAME);
100 json_attr_string (&json_ctx, "bench-variant", "default");
102 json_array_begin (&json_ctx, "ifuncs");
103 FOR_EACH_IMPL (impl, 0)
104 json_element_string (&json_ctx, impl->name);
105 json_array_end (&json_ctx);
107 json_array_begin (&json_ctx, "results");
109 for (c = -65; c <= 130; c += 65)
111 for (i = 0; i < 18; ++i)
112 do_test (&json_ctx, 0, c, 1 << i);
113 for (i = 1; i < 32; ++i)
115 do_test (&json_ctx, i, c, i);
117 do_test (&json_ctx, 0, c, i);
119 for (i = 32; i < 512; i+=32)
121 do_test (&json_ctx, 0, c, i);
122 do_test (&json_ctx, i, c, i);
124 do_test (&json_ctx, 1, c, 14);
125 do_test (&json_ctx, 3, c, 1024);
126 do_test (&json_ctx, 4, c, 64);
127 do_test (&json_ctx, 2, c, 25);
129 for (i = 33; i <= 256; i += 4)
131 do_test (&json_ctx, 0, c, 32 * i);
132 do_test (&json_ctx, i, c, 32 * i);
135 json_array_end (&json_ctx);
136 json_attr_object_end (&json_ctx);
137 json_attr_object_end (&json_ctx);
138 json_document_end (&json_ctx);
143 #include <support/test-driver.c>
145 #define libc_hidden_builtin_def(X)
146 #define libc_hidden_def(X)
147 #define libc_hidden_weak(X)
148 #define weak_alias(X,Y)
151 # define MEMSET generic_memset
152 # include <string/memset.c>
154 # define WMEMSET generic_wmemset
155 # include <wcsmbs/wmemset.c>