1 /* Measure strcasecmp functions.
2 Copyright (C) 2013-2021 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"
24 typedef int (*proto_t
) (const char *, const char *);
25 static int simple_strcasecmp (const char *, const char *);
27 IMPL (simple_strcasecmp
, 0)
31 simple_strcasecmp (const char *s1
, const char *s2
)
35 while ((ret
= ((unsigned char) tolower (*s1
)
36 - (unsigned char) tolower (*s2
))) == 0
43 do_one_test (impl_t
*impl
, const char *s1
, const char *s2
, int exp_result
)
45 size_t i
, iters
= INNER_LOOP_ITERS
;
46 timing_t start
, stop
, cur
;
47 int result
= CALL (impl
, s1
, s2
);
48 if ((exp_result
== 0 && result
!= 0)
49 || (exp_result
< 0 && result
>= 0)
50 || (exp_result
> 0 && result
<= 0))
52 error (0, 0, "Wrong result in function %s %d %d", impl
->name
,
59 for (i
= 0; i
< iters
; ++i
)
65 TIMING_DIFF (cur
, start
, stop
);
67 TIMING_PRINT_MEAN ((double) cur
, (double) iters
);
71 do_test (size_t align1
, size_t align2
, size_t len
, int max_char
,
81 if (align1
+ len
+ 1 >= page_size
)
85 if (align2
+ len
+ 1 >= page_size
)
88 s1
= (char *) (buf1
+ align1
);
89 s2
= (char *) (buf2
+ align2
);
91 for (i
= 0; i
< len
; i
++)
93 s1
[i
] = toupper (1 + 23 * i
% max_char
);
94 s2
[i
] = tolower (s1
[i
]);
97 s1
[len
] = s2
[len
] = 0;
99 s2
[len
+ 1] = 24 + exp_result
;
100 if ((s2
[len
- 1] == 'z' && exp_result
== -1)
101 || (s2
[len
- 1] == 'a' && exp_result
== 1))
102 s1
[len
- 1] += exp_result
;
104 s2
[len
- 1] -= exp_result
;
106 printf ("Length %4zd, alignment %2zd/%2zd:", len
, align1
, align2
);
108 FOR_EACH_IMPL (impl
, 0)
109 do_one_test (impl
, s1
, s2
, exp_result
);
122 FOR_EACH_IMPL (impl
, 0)
123 printf ("\t%s", impl
->name
);
126 for (i
= 1; i
< 16; ++i
)
128 do_test (i
, i
, i
, 127, 0);
129 do_test (i
, i
, i
, 127, 1);
130 do_test (i
, i
, i
, 127, -1);
133 for (i
= 1; i
< 10; ++i
)
135 do_test (0, 0, 2 << i
, 127, 0);
136 do_test (0, 0, 2 << i
, 254, 0);
137 do_test (0, 0, 2 << i
, 127, 1);
138 do_test (0, 0, 2 << i
, 254, 1);
139 do_test (0, 0, 2 << i
, 127, -1);
140 do_test (0, 0, 2 << i
, 254, -1);
143 for (i
= 1; i
< 8; ++i
)
145 do_test (i
, 2 * i
, 8 << i
, 127, 0);
146 do_test (2 * i
, i
, 8 << i
, 254, 0);
147 do_test (i
, 2 * i
, 8 << i
, 127, 1);
148 do_test (2 * i
, i
, 8 << i
, 254, 1);
149 do_test (i
, 2 * i
, 8 << i
, 127, -1);
150 do_test (2 * i
, i
, 8 << i
, 254, -1);
156 #include <support/test-driver.c>