1 /* Measure strncasecmp functions.
2 Copyright (C) 2013-2022 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 "strncasecmp"
22 #include "bench-string.h"
25 typedef int (*proto_t
) (const char *, const char *, size_t);
26 static int simple_strncasecmp (const char *, const char *, size_t);
28 IMPL (simple_strncasecmp
, 0)
32 simple_strncasecmp (const char *s1
, const char *s2
, size_t n
)
39 while ((ret
= ((unsigned char) tolower (*s1
)
40 - (unsigned char) tolower (*s2
))) == 0
51 do_one_test (json_ctx_t
*json_ctx
, impl_t
*impl
, const char *s1
,
52 const char *s2
, size_t n
, int exp_result
)
54 size_t i
, iters
= INNER_LOOP_ITERS
;
55 timing_t start
, stop
, cur
;
58 for (i
= 0; i
< iters
; ++i
)
60 CALL (impl
, s1
, s2
, n
);
64 TIMING_DIFF (cur
, start
, stop
);
66 json_element_double (json_ctx
, (double) cur
/ (double) iters
);
70 do_test (json_ctx_t
*json_ctx
, size_t align1
, size_t align2
, size_t n
,
71 size_t len
, int max_char
, int exp_result
)
80 if (align1
+ len
+ 1 >= page_size
)
84 if (align2
+ len
+ 1 >= page_size
)
87 s1
= (char *) (buf1
+ align1
);
88 s2
= (char *) (buf2
+ align2
);
90 for (i
= 0; i
< len
; i
++)
92 s1
[i
] = toupper (1 + 23 * i
% max_char
);
93 s2
[i
] = tolower (s1
[i
]);
96 s1
[len
] = s2
[len
] = 0;
98 s2
[len
+ 1] = 24 + exp_result
;
99 if ((s2
[len
- 1] == 'z' && exp_result
== -1)
100 || (s2
[len
- 1] == 'a' && exp_result
== 1))
101 s1
[len
- 1] += exp_result
;
103 s2
[len
- 1] -= exp_result
;
105 json_element_object_begin (json_ctx
);
106 json_attr_uint (json_ctx
, "length", len
);
107 json_attr_uint (json_ctx
, "n", n
);
108 json_attr_uint (json_ctx
, "align1", align1
);
109 json_attr_uint (json_ctx
, "align2", align2
);
110 json_attr_uint (json_ctx
, "max_char", max_char
);
111 json_array_begin (json_ctx
, "timings");
113 FOR_EACH_IMPL (impl
, 0)
114 do_one_test (json_ctx
, impl
, s1
, s2
, n
, exp_result
);
116 json_array_end (json_ctx
);
117 json_element_object_end (json_ctx
);
128 json_init (&json_ctx
, 0, stdout
);
130 json_document_begin (&json_ctx
);
131 json_attr_string (&json_ctx
, "timing_type", TIMING_TYPE
);
133 json_attr_object_begin (&json_ctx
, "functions");
134 json_attr_object_begin (&json_ctx
, TEST_NAME
);
135 json_attr_string (&json_ctx
, "bench-variant", "");
137 json_array_begin (&json_ctx
, "ifuncs");
138 FOR_EACH_IMPL (impl
, 0)
139 json_element_string (&json_ctx
, impl
->name
);
140 json_array_end (&json_ctx
);
142 json_array_begin (&json_ctx
, "results");
144 for (i
= 1; i
< 16; ++i
)
146 do_test (&json_ctx
, i
, i
, i
- 1, i
, 127, 0);
148 do_test (&json_ctx
, i
, i
, i
, i
, 127, 0);
149 do_test (&json_ctx
, i
, i
, i
, i
, 127, 1);
150 do_test (&json_ctx
, i
, i
, i
, i
, 127, -1);
152 do_test (&json_ctx
, i
, i
, i
+ 1, i
, 127, 0);
153 do_test (&json_ctx
, i
, i
, i
+ 1, i
, 127, 1);
154 do_test (&json_ctx
, i
, i
, i
+ 1, i
, 127, -1);
157 for (i
= 1; i
< 10; ++i
)
159 do_test (&json_ctx
, 0, 0, (2 << i
) - 1, 2 << i
, 127, 0);
160 do_test (&json_ctx
, 0, 0, 2 << i
, 2 << i
, 254, 0);
161 do_test (&json_ctx
, 0, 0, (2 << i
) + 1, 2 << i
, 127, 0);
163 do_test (&json_ctx
, 0, 0, (2 << i
) + 1, 2 << i
, 254, 0);
165 do_test (&json_ctx
, 0, 0, 2 << i
, 2 << i
, 127, 1);
166 do_test (&json_ctx
, 0, 0, (2 << i
) + 10, 2 << i
, 127, 1);
168 do_test (&json_ctx
, 0, 0, 2 << i
, 2 << i
, 254, 1);
169 do_test (&json_ctx
, 0, 0, (2 << i
) + 10, 2 << i
, 254, 1);
171 do_test (&json_ctx
, 0, 0, 2 << i
, 2 << i
, 127, -1);
172 do_test (&json_ctx
, 0, 0, (2 << i
) + 10, 2 << i
, 127, -1);
174 do_test (&json_ctx
, 0, 0, 2 << i
, 2 << i
, 254, -1);
175 do_test (&json_ctx
, 0, 0, (2 << i
) + 10, 2 << i
, 254, -1);
178 for (i
= 1; i
< 8; ++i
)
180 do_test (&json_ctx
, i
, 2 * i
, (8 << i
) - 1, 8 << i
, 127, 0);
181 do_test (&json_ctx
, i
, 2 * i
, 8 << i
, 8 << i
, 127, 0);
182 do_test (&json_ctx
, i
, 2 * i
, (8 << i
) + 100, 8 << i
, 127, 0);
184 do_test (&json_ctx
, 2 * i
, i
, (8 << i
) - 1, 8 << i
, 254, 0);
185 do_test (&json_ctx
, 2 * i
, i
, 8 << i
, 8 << i
, 254, 0);
186 do_test (&json_ctx
, 2 * i
, i
, (8 << i
) + 100, 8 << i
, 254, 0);
188 do_test (&json_ctx
, i
, 2 * i
, 8 << i
, 8 << i
, 127, 1);
189 do_test (&json_ctx
, i
, 2 * i
, (8 << i
) + 100, 8 << i
, 127, 1);
191 do_test (&json_ctx
, 2 * i
, i
, 8 << i
, 8 << i
, 254, 1);
192 do_test (&json_ctx
, 2 * i
, i
, (8 << i
) + 100, 8 << i
, 254, 1);
194 do_test (&json_ctx
, i
, 2 * i
, 8 << i
, 8 << i
, 127, -1);
195 do_test (&json_ctx
, i
, 2 * i
, (8 << i
) + 100, 8 << i
, 127, -1);
197 do_test (&json_ctx
, 2 * i
, i
, 8 << i
, 8 << i
, 254, -1);
198 do_test (&json_ctx
, 2 * i
, i
, (8 << i
) + 100, 8 << i
, 254, -1);
201 json_array_end (&json_ctx
);
202 json_attr_object_end (&json_ctx
);
203 json_attr_object_end (&json_ctx
);
204 json_document_end (&json_ctx
);
209 #include <support/test-driver.c>