1 | /* Measure memset functions. |
2 | Copyright (C) 2013-2022 Free Software Foundation, Inc. |
3 | This file is part of the GNU C Library. |
4 | |
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. |
9 | |
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. |
14 | |
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/>. */ |
18 | |
19 | #define TEST_MAIN |
20 | #ifndef WIDE |
21 | # define TEST_NAME "memset" |
22 | #else |
23 | # define TEST_NAME "wmemset" |
24 | # define generic_memset generic_wmemset |
25 | #endif /* WIDE */ |
26 | #define MIN_PAGE_SIZE 131072 |
27 | #include "bench-string.h" |
28 | |
29 | #include "json-lib.h" |
30 | |
31 | #ifdef WIDE |
32 | CHAR *generic_wmemset (CHAR *, CHAR, size_t); |
33 | #else |
34 | void *generic_memset (void *, int, size_t); |
35 | #endif |
36 | |
37 | typedef void *(*proto_t) (void *, int, size_t); |
38 | |
39 | IMPL (MEMSET, 1) |
40 | IMPL (generic_memset, 0) |
41 | |
42 | static void |
43 | do_one_test (json_ctx_t *json_ctx, impl_t *impl, CHAR *s, |
44 | int c __attribute ((unused)), size_t n) |
45 | { |
46 | size_t i, iters = INNER_LOOP_ITERS_LARGE; |
47 | timing_t start, stop, cur; |
48 | |
49 | TIMING_NOW (start); |
50 | for (i = 0; i < iters; ++i) |
51 | { |
52 | CALL (impl, s, c, n); |
53 | } |
54 | TIMING_NOW (stop); |
55 | |
56 | TIMING_DIFF (cur, start, stop); |
57 | |
58 | json_element_double (ctx: json_ctx, d: (double) cur / (double) iters); |
59 | } |
60 | |
61 | static void |
62 | do_test (json_ctx_t *json_ctx, size_t align, int c, size_t len) |
63 | { |
64 | align &= 4095; |
65 | if ((align + len) * sizeof (CHAR) > page_size) |
66 | return; |
67 | |
68 | json_element_object_begin (ctx: json_ctx); |
69 | json_attr_uint (ctx: json_ctx, name: "length" , d: len); |
70 | json_attr_uint (ctx: json_ctx, name: "alignment" , d: align); |
71 | json_attr_int (ctx: json_ctx, name: "char" , d: c); |
72 | json_array_begin (ctx: json_ctx, name: "timings" ); |
73 | |
74 | FOR_EACH_IMPL (impl, 0) |
75 | { |
76 | do_one_test (json_ctx, impl, s: (CHAR *) (buf1) + align, c, n: len); |
77 | alloc_bufs (); |
78 | } |
79 | |
80 | json_array_end (ctx: json_ctx); |
81 | json_element_object_end (ctx: json_ctx); |
82 | } |
83 | |
84 | int |
85 | test_main (void) |
86 | { |
87 | json_ctx_t json_ctx; |
88 | size_t i; |
89 | int c = 0; |
90 | |
91 | test_init (); |
92 | |
93 | json_init (ctx: &json_ctx, indent_level: 0, stdout); |
94 | |
95 | json_document_begin (ctx: &json_ctx); |
96 | json_attr_string (ctx: &json_ctx, name: "timing_type" , TIMING_TYPE); |
97 | |
98 | json_attr_object_begin (ctx: &json_ctx, name: "functions" ); |
99 | json_attr_object_begin (ctx: &json_ctx, TEST_NAME); |
100 | json_attr_string (ctx: &json_ctx, name: "bench-variant" , s: "default" ); |
101 | |
102 | json_array_begin (ctx: &json_ctx, name: "ifuncs" ); |
103 | FOR_EACH_IMPL (impl, 0) |
104 | json_element_string (ctx: &json_ctx, s: impl->name); |
105 | json_array_end (ctx: &json_ctx); |
106 | |
107 | json_array_begin (ctx: &json_ctx, name: "results" ); |
108 | |
109 | for (c = -65; c <= 130; c += 65) |
110 | { |
111 | for (i = 0; i < 18; ++i) |
112 | do_test (json_ctx: &json_ctx, align: 0, c, len: 1 << i); |
113 | for (i = 1; i < 64; ++i) |
114 | { |
115 | do_test (json_ctx: &json_ctx, align: i, c, len: i); |
116 | do_test (json_ctx: &json_ctx, align: 4096 - i, c, len: i); |
117 | do_test (json_ctx: &json_ctx, align: 4095, c, len: i); |
118 | if (i & (i - 1)) |
119 | do_test (json_ctx: &json_ctx, align: 0, c, len: i); |
120 | } |
121 | for (i = 32; i < 1024; i+=32) |
122 | { |
123 | do_test (json_ctx: &json_ctx, align: 0, c, len: i); |
124 | do_test (json_ctx: &json_ctx, align: i, c, len: i); |
125 | } |
126 | do_test (json_ctx: &json_ctx, align: 1, c, len: 14); |
127 | do_test (json_ctx: &json_ctx, align: 3, c, len: 1024); |
128 | do_test (json_ctx: &json_ctx, align: 4, c, len: 64); |
129 | do_test (json_ctx: &json_ctx, align: 2, c, len: 25); |
130 | } |
131 | for (i = 33; i <= 256; i += 4) |
132 | { |
133 | do_test (json_ctx: &json_ctx, align: 0, c, len: 32 * i); |
134 | do_test (json_ctx: &json_ctx, align: i, c, len: 32 * i); |
135 | } |
136 | |
137 | json_array_end (ctx: &json_ctx); |
138 | json_attr_object_end (ctx: &json_ctx); |
139 | json_attr_object_end (ctx: &json_ctx); |
140 | json_document_end (ctx: &json_ctx); |
141 | |
142 | return ret; |
143 | } |
144 | |
145 | #include <support/test-driver.c> |
146 | |
147 | #define libc_hidden_builtin_def(X) |
148 | #define libc_hidden_def(X) |
149 | #define libc_hidden_weak(X) |
150 | #define weak_alias(X,Y) |
151 | #ifndef WIDE |
152 | # undef MEMSET |
153 | # define MEMSET generic_memset |
154 | # include <string/memset.c> |
155 | #else |
156 | # define WMEMSET generic_wmemset |
157 | # include <wcsmbs/wmemset.c> |
158 | #endif |
159 | |