1 /* Measure strcasecmp 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 "strcasecmp"
22 #include "bench-string.h"
25 typedef int (*proto_t
) (const char *, const char *);
30 do_one_test (json_ctx_t
*json_ctx
, impl_t
*impl
, const char *s1
,
31 const char *s2
, int exp_result
)
33 size_t i
, iters
= INNER_LOOP_ITERS8
;
34 timing_t start
, stop
, cur
;
35 int result
= CALL (impl
, s1
, s2
);
36 if ((exp_result
== 0 && result
!= 0)
37 || (exp_result
< 0 && result
>= 0)
38 || (exp_result
> 0 && result
<= 0))
40 error (0, 0, "Wrong result in function %s %d %d", impl
->name
,
47 for (i
= 0; i
< iters
; ++i
)
53 TIMING_DIFF (cur
, start
, stop
);
55 json_element_double (json_ctx
, (double) cur
/ (double) iters
);
59 do_test (json_ctx_t
*json_ctx
, size_t align1
, size_t align2
, size_t len
,
60 int max_char
, int exp_result
)
69 if (align1
+ len
+ 1 >= page_size
)
73 if (align2
+ len
+ 1 >= page_size
)
76 json_element_object_begin (json_ctx
);
77 json_attr_uint (json_ctx
, "length", len
);
78 json_attr_uint (json_ctx
, "align1", align1
);
79 json_attr_uint (json_ctx
, "align2", align2
);
80 json_attr_uint (json_ctx
, "max_char", max_char
);
81 json_array_begin (json_ctx
, "timings");
83 s1
= (char *) (buf1
+ align1
);
84 s2
= (char *) (buf2
+ align2
);
86 for (i
= 0; i
< len
; i
++)
88 s1
[i
] = toupper (1 + 23 * i
% max_char
);
89 s2
[i
] = tolower (s1
[i
]);
92 s1
[len
] = s2
[len
] = 0;
94 s2
[len
+ 1] = 24 + exp_result
;
95 if ((s2
[len
- 1] == 'z' && exp_result
== -1)
96 || (s2
[len
- 1] == 'a' && exp_result
== 1))
97 s1
[len
- 1] += exp_result
;
99 s2
[len
- 1] -= exp_result
;
101 FOR_EACH_IMPL (impl
, 0)
102 do_one_test (json_ctx
, impl
, s1
, s2
, exp_result
);
104 json_array_end (json_ctx
);
105 json_element_object_end (json_ctx
);
116 json_init (&json_ctx
, 0, stdout
);
118 json_document_begin (&json_ctx
);
119 json_attr_string (&json_ctx
, "timing_type", TIMING_TYPE
);
121 json_attr_object_begin (&json_ctx
, "functions");
122 json_attr_object_begin (&json_ctx
, TEST_NAME
);
123 json_attr_string (&json_ctx
, "bench-variant", "");
125 json_array_begin (&json_ctx
, "ifuncs");
126 FOR_EACH_IMPL (impl
, 0)
127 json_element_string (&json_ctx
, impl
->name
);
128 json_array_end (&json_ctx
);
130 json_array_begin (&json_ctx
, "results");
132 for (i
= 1; i
< 16; ++i
)
134 do_test (&json_ctx
, i
, i
, i
, 127, 0);
135 do_test (&json_ctx
, i
, i
, i
, 127, 1);
136 do_test (&json_ctx
, i
, i
, i
, 127, -1);
139 for (i
= 1; i
< 10; ++i
)
141 do_test (&json_ctx
, 0, 0, 2 << i
, 127, 0);
142 do_test (&json_ctx
, 0, 0, 2 << i
, 254, 0);
143 do_test (&json_ctx
, 0, 0, 2 << i
, 127, 1);
144 do_test (&json_ctx
, 0, 0, 2 << i
, 254, 1);
145 do_test (&json_ctx
, 0, 0, 2 << i
, 127, -1);
146 do_test (&json_ctx
, 0, 0, 2 << i
, 254, -1);
149 for (i
= 1; i
< 8; ++i
)
151 do_test (&json_ctx
, i
, 2 * i
, 8 << i
, 127, 0);
152 do_test (&json_ctx
, 2 * i
, i
, 8 << i
, 254, 0);
153 do_test (&json_ctx
, i
, 2 * i
, 8 << i
, 127, 1);
154 do_test (&json_ctx
, 2 * i
, i
, 8 << i
, 254, 1);
155 do_test (&json_ctx
, i
, 2 * i
, 8 << i
, 127, -1);
156 do_test (&json_ctx
, 2 * i
, i
, 8 << i
, 254, -1);
159 json_array_end (&json_ctx
);
160 json_attr_object_end (&json_ctx
);
161 json_attr_object_end (&json_ctx
);
162 json_document_end (&json_ctx
);
167 #include <support/test-driver.c>