1 /* Measure strcat functions.
2 Copyright (C) 2013-2023 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 "strcat"
23 # define TEST_NAME "wcscat"
24 # define generic_strcat generic_wcscat
26 #include "bench-string.h"
28 #define BIG_CHAR MAX_CHAR
32 # define SMALL_CHAR 127
35 # define SMALL_CHAR 1273
40 typedef CHAR
*(*proto_t
) (CHAR
*, const CHAR
*);
43 generic_strcat (CHAR
*dst
, const CHAR
*src
)
45 STRCPY (dst
+ STRLEN (dst
), src
);
50 IMPL (generic_strcat
, 0)
53 do_one_test (json_ctx_t
*json_ctx
, impl_t
*impl
, CHAR
*dst
, const CHAR
*src
)
55 size_t k
= STRLEN (dst
), i
, iters
= INNER_LOOP_ITERS_LARGE
/ CHARBYTES
;
56 timing_t start
, stop
, cur
;
58 if (CALL (impl
, dst
, src
) != dst
)
60 error (0, 0, "Wrong result in function %s %p %p", impl
->name
,
61 CALL (impl
, dst
, src
), dst
);
66 if (STRCMP (dst
+ k
, src
) != 0)
69 "Wrong result in function %s dst \"%" sfmt
"\" src \"%" sfmt
"\"",
70 impl
->name
, dst
, src
);
76 for (i
= 0; i
< iters
; ++i
)
79 CALL (impl
, dst
, src
);
83 TIMING_DIFF (cur
, start
, stop
);
85 json_element_double (json_ctx
, (double) cur
/ (double) iters
);
89 do_test (json_ctx_t
*json_ctx
, size_t align1
, size_t align2
, size_t len1
,
90 size_t len2
, int max_char
)
96 if ((align1
+ len1
) * sizeof (CHAR
) >= page_size
)
100 if ((align2
+ len1
+ len2
) * sizeof (CHAR
) >= page_size
)
103 s1
= (CHAR
*) (buf1
) + align1
;
104 s2
= (CHAR
*) (buf2
) + align2
;
106 for (i
= 0; i
< len1
; ++i
)
107 s1
[i
] = 32 + 23 * i
% (max_char
- 32);
110 for (i
= 0; i
< len2
; i
++)
111 s2
[i
] = 32 + 23 * i
% (max_char
- 32);
113 json_element_object_begin (json_ctx
);
114 json_attr_uint (json_ctx
, "align1", align1
);
115 json_attr_uint (json_ctx
, "align2", align2
);
116 json_attr_uint (json_ctx
, "len1", len1
);
117 json_attr_uint (json_ctx
, "len2", len2
);
118 json_attr_uint (json_ctx
, "max_char", max_char
);
120 json_array_begin (json_ctx
, "timings");
122 FOR_EACH_IMPL (impl
, 0)
125 do_one_test (json_ctx
, impl
, s2
, s1
);
128 json_array_end (json_ctx
);
129 json_element_object_end (json_ctx
);
142 json_init (&json_ctx
, 0, stdout
);
144 json_document_begin (&json_ctx
);
145 json_attr_string (&json_ctx
, "timing_type", TIMING_TYPE
);
147 json_attr_object_begin (&json_ctx
, "functions");
148 json_attr_object_begin (&json_ctx
, TEST_NAME
);
149 json_attr_string (&json_ctx
, "bench-variant", "");
151 json_array_begin (&json_ctx
, "ifuncs");
152 FOR_EACH_IMPL (impl
, 0)
153 json_element_string (&json_ctx
, impl
->name
);
154 json_array_end (&json_ctx
);
156 json_array_begin (&json_ctx
, "results");
158 for (i
= 0; i
< 16; ++i
)
160 do_test (&json_ctx
, 0, 0, i
, i
, SMALL_CHAR
);
161 do_test (&json_ctx
, 0, 0, i
, i
, BIG_CHAR
);
162 do_test (&json_ctx
, 0, i
, i
, i
, SMALL_CHAR
);
163 do_test (&json_ctx
, i
, 0, i
, i
, BIG_CHAR
);
166 for (i
= 1; i
< 8; ++i
)
168 do_test (&json_ctx
, 0, 0, 8 << i
, 8 << i
, SMALL_CHAR
);
169 do_test (&json_ctx
, 8 - i
, 2 * i
, 8 << i
, 8 << i
, SMALL_CHAR
);
170 do_test (&json_ctx
, 0, 0, 8 << i
, 2 << i
, SMALL_CHAR
);
171 do_test (&json_ctx
, 8 - i
, 2 * i
, 8 << i
, 2 << i
, SMALL_CHAR
);
174 for (i
= 1; i
< 8; ++i
)
176 do_test (&json_ctx
, i
, 2 * i
, 8 << i
, 1, SMALL_CHAR
);
177 do_test (&json_ctx
, 2 * i
, i
, 8 << i
, 1, BIG_CHAR
);
178 do_test (&json_ctx
, i
, i
, 8 << i
, 10, SMALL_CHAR
);
179 do_test (&json_ctx
, i
, i
, 8 << i
, 10, BIG_CHAR
);
182 for (i
= 32; i
< 256; i
+= 32)
184 do_test (&json_ctx
, 1, 0, i
, 31, SMALL_CHAR
);
185 do_test (&json_ctx
, 0, i
, i
, 31, SMALL_CHAR
);
186 do_test (&json_ctx
, 0, 0, i
, 31, SMALL_CHAR
);
187 do_test (&json_ctx
, i
, i
, i
, 31, SMALL_CHAR
);
190 for (; i
< 512; i
+= 64)
192 do_test (&json_ctx
, 1, 0, i
, 31, SMALL_CHAR
);
193 do_test (&json_ctx
, 0, i
, i
, 31, SMALL_CHAR
);
194 do_test (&json_ctx
, 0, 0, i
, 31, SMALL_CHAR
);
195 do_test (&json_ctx
, i
, i
, i
, 31, SMALL_CHAR
);
198 for (; i
< 1024; i
+= 128)
200 do_test (&json_ctx
, 1, 0, i
, 31, SMALL_CHAR
);
201 do_test (&json_ctx
, 0, i
, i
, 31, SMALL_CHAR
);
202 do_test (&json_ctx
, 0, 0, i
, 31, SMALL_CHAR
);
203 do_test (&json_ctx
, i
, i
, i
, 31, SMALL_CHAR
);
206 for (; i
< 2048; i
+= 256)
208 do_test (&json_ctx
, 1, 0, i
, 31, SMALL_CHAR
);
209 do_test (&json_ctx
, 0, i
, i
, 31, SMALL_CHAR
);
210 do_test (&json_ctx
, 0, 0, i
, 31, SMALL_CHAR
);
211 do_test (&json_ctx
, i
, i
, i
, 31, SMALL_CHAR
);
214 json_array_end (&json_ctx
);
215 json_attr_object_end (&json_ctx
);
216 json_attr_object_end (&json_ctx
);
217 json_document_end (&json_ctx
);
222 #include <support/test-driver.c>