]> sourceware.org Git - glibc.git/blame - benchtests/bench-strcat.c
benchtests: Make str{n}{cat|cpy} benchmarks output json
[glibc.git] / benchtests / bench-strcat.c
CommitLineData
97020474 1/* Measure strcat functions.
581c785b 2 Copyright (C) 2013-2022 Free Software Foundation, Inc.
97020474
SP
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
5a82c748 17 <https://www.gnu.org/licenses/>. */
97020474
SP
18
19#define TEST_MAIN
d626a24f
SL
20#ifndef WIDE
21# define TEST_NAME "strcat"
22#else
23# define TEST_NAME "wcscat"
648279f4 24# define generic_strcat generic_wcscat
d626a24f 25#endif /* WIDE */
97020474
SP
26#include "bench-string.h"
27
90d3320d
WD
28#define BIG_CHAR MAX_CHAR
29
d626a24f 30#ifndef WIDE
d626a24f 31# define sfmt "s"
d626a24f
SL
32# define SMALL_CHAR 127
33#else
d626a24f 34# define sfmt "ls"
d626a24f
SL
35# define SMALL_CHAR 1273
36#endif /* WIDE */
37
d44e1164 38#include "json-lib.h"
d626a24f
SL
39
40typedef CHAR *(*proto_t) (CHAR *, const CHAR *);
d626a24f
SL
41
42CHAR *
648279f4 43generic_strcat (CHAR *dst, const CHAR *src)
97020474 44{
648279f4
WD
45 STRCPY (dst + STRLEN (dst), src);
46 return dst;
97020474
SP
47}
48
648279f4
WD
49IMPL (STRCAT, 1)
50IMPL (generic_strcat, 0)
51
97020474 52static void
d44e1164 53do_one_test (json_ctx_t *json_ctx, impl_t *impl, CHAR *dst, const CHAR *src)
97020474 54{
afe23eb0 55 size_t k = STRLEN (dst), i, iters = INNER_LOOP_ITERS_LARGE;
44558701
WN
56 timing_t start, stop, cur;
57
97020474
SP
58 if (CALL (impl, dst, src) != dst)
59 {
60 error (0, 0, "Wrong result in function %s %p %p", impl->name,
61 CALL (impl, dst, src), dst);
62 ret = 1;
63 return;
64 }
65
d626a24f 66 if (STRCMP (dst + k, src) != 0)
97020474 67 {
d44e1164
NG
68 error (0, 0,
69 "Wrong result in function %s dst \"%" sfmt "\" src \"%" sfmt "\"",
97020474
SP
70 impl->name, dst, src);
71 ret = 1;
72 return;
73 }
74
44558701
WN
75 TIMING_NOW (start);
76 for (i = 0; i < iters; ++i)
97020474 77 {
44558701
WN
78 dst[k] = '\0';
79 CALL (impl, dst, src);
97020474 80 }
44558701
WN
81 TIMING_NOW (stop);
82
83 TIMING_DIFF (cur, start, stop);
84
d44e1164 85 json_element_double (json_ctx, (double) cur / (double) iters);
97020474
SP
86}
87
88static void
d44e1164
NG
89do_test (json_ctx_t *json_ctx, size_t align1, size_t align2, size_t len1,
90 size_t len2, int max_char)
97020474
SP
91{
92 size_t i;
d626a24f 93 CHAR *s1, *s2;
97020474
SP
94
95 align1 &= 7;
d626a24f 96 if ((align1 + len1) * sizeof (CHAR) >= page_size)
97020474
SP
97 return;
98
99 align2 &= 7;
d626a24f 100 if ((align2 + len1 + len2) * sizeof (CHAR) >= page_size)
97020474
SP
101 return;
102
d626a24f
SL
103 s1 = (CHAR *) (buf1) + align1;
104 s2 = (CHAR *) (buf2) + align2;
97020474
SP
105
106 for (i = 0; i < len1; ++i)
107 s1[i] = 32 + 23 * i % (max_char - 32);
108 s1[len1] = '\0';
109
110 for (i = 0; i < len2; i++)
111 s2[i] = 32 + 23 * i % (max_char - 32);
112
d44e1164
NG
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);
119
120 json_array_begin (json_ctx, "timings");
97020474
SP
121
122 FOR_EACH_IMPL (impl, 0)
123 {
124 s2[len2] = '\0';
d44e1164 125 do_one_test (json_ctx, impl, s2, s1);
97020474
SP
126 }
127
d44e1164
NG
128 json_array_end (json_ctx);
129 json_element_object_end (json_ctx);
97020474
SP
130}
131
132int
133test_main (void)
134{
d44e1164 135 json_ctx_t json_ctx;
97020474
SP
136 size_t i;
137
138 test_init ();
139
d44e1164
NG
140 test_init ();
141
142 json_init (&json_ctx, 0, stdout);
143
144 json_document_begin (&json_ctx);
145 json_attr_string (&json_ctx, "timing_type", TIMING_TYPE);
146
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", "");
150
151 json_array_begin (&json_ctx, "ifuncs");
97020474 152 FOR_EACH_IMPL (impl, 0)
d44e1164
NG
153 json_element_string (&json_ctx, impl->name);
154 json_array_end (&json_ctx);
155
156 json_array_begin (&json_ctx, "results");
97020474
SP
157
158 for (i = 0; i < 16; ++i)
159 {
d44e1164
NG
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);
97020474
SP
164 }
165
166 for (i = 1; i < 8; ++i)
167 {
d44e1164
NG
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);
97020474
SP
172 }
173
174 for (i = 1; i < 8; ++i)
175 {
d44e1164
NG
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);
180 }
181
182 for (i = 32; i < 256; i += 32)
183 {
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);
97020474
SP
188 }
189
d44e1164
NG
190 for (; i < 512; i += 64)
191 {
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);
196 }
197
198 for (; i < 1024; i += 128)
199 {
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);
204 }
205
206 for (; i < 2048; i += 256)
207 {
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);
212 }
213
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);
218
97020474
SP
219 return ret;
220}
221
b598e134 222#include <support/test-driver.c>
This page took 0.221256 seconds and 5 git commands to generate.