]>
git.ipfire.org Git - thirdparty/glibc.git/blob - benchtests/bench-strncasecmp.c
1 /* Measure strncasecmp functions.
2 Copyright (C) 2013-2019 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 <http://www.gnu.org/licenses/>. */
21 #define TEST_NAME "strncasecmp"
22 #include "bench-string.h"
24 typedef int (*proto_t
) (const char *, const char *, size_t);
25 static int simple_strncasecmp (const char *, const char *, size_t);
27 IMPL (simple_strncasecmp
, 0)
31 simple_strncasecmp (const char *s1
, const char *s2
, size_t n
)
38 while ((ret
= ((unsigned char) tolower (*s1
)
39 - (unsigned char) tolower (*s2
))) == 0
50 do_one_test (impl_t
*impl
, const char *s1
, const char *s2
, size_t n
,
53 size_t i
, iters
= INNER_LOOP_ITERS
;
54 timing_t start
, stop
, cur
;
57 for (i
= 0; i
< iters
; ++i
)
59 CALL (impl
, s1
, s2
, n
);
63 TIMING_DIFF (cur
, start
, stop
);
65 TIMING_PRINT_MEAN ((double) cur
, (double) iters
);
69 do_test (size_t align1
, size_t align2
, size_t n
, size_t len
, int max_char
,
79 if (align1
+ len
+ 1 >= page_size
)
83 if (align2
+ len
+ 1 >= page_size
)
86 s1
= (char *) (buf1
+ align1
);
87 s2
= (char *) (buf2
+ align2
);
89 for (i
= 0; i
< len
; i
++)
91 s1
[i
] = toupper (1 + 23 * i
% max_char
);
92 s2
[i
] = tolower (s1
[i
]);
95 s1
[len
] = s2
[len
] = 0;
97 s2
[len
+ 1] = 24 + exp_result
;
98 if ((s2
[len
- 1] == 'z' && exp_result
== -1)
99 || (s2
[len
- 1] == 'a' && exp_result
== 1))
100 s1
[len
- 1] += exp_result
;
102 s2
[len
- 1] -= exp_result
;
104 printf ("Length %4zd, alignment %2zd/%2zd:", len
, align1
, align2
);
106 FOR_EACH_IMPL (impl
, 0)
107 do_one_test (impl
, s1
, s2
, n
, exp_result
);
120 FOR_EACH_IMPL (impl
, 0)
121 printf ("\t%s", impl
->name
);
124 for (i
= 1; i
< 16; ++i
)
126 do_test (i
, i
, i
- 1, i
, 127, 0);
128 do_test (i
, i
, i
, i
, 127, 0);
129 do_test (i
, i
, i
, i
, 127, 1);
130 do_test (i
, i
, i
, i
, 127, -1);
132 do_test (i
, i
, i
+ 1, i
, 127, 0);
133 do_test (i
, i
, i
+ 1, i
, 127, 1);
134 do_test (i
, i
, i
+ 1, i
, 127, -1);
137 for (i
= 1; i
< 10; ++i
)
139 do_test (0, 0, (2 << i
) - 1, 2 << i
, 127, 0);
140 do_test (0, 0, 2 << i
, 2 << i
, 254, 0);
141 do_test (0, 0, (2 << i
) + 1, 2 << i
, 127, 0);
143 do_test (0, 0, (2 << i
) + 1, 2 << i
, 254, 0);
145 do_test (0, 0, 2 << i
, 2 << i
, 127, 1);
146 do_test (0, 0, (2 << i
) + 10, 2 << i
, 127, 1);
148 do_test (0, 0, 2 << i
, 2 << i
, 254, 1);
149 do_test (0, 0, (2 << i
) + 10, 2 << i
, 254, 1);
151 do_test (0, 0, 2 << i
, 2 << i
, 127, -1);
152 do_test (0, 0, (2 << i
) + 10, 2 << i
, 127, -1);
154 do_test (0, 0, 2 << i
, 2 << i
, 254, -1);
155 do_test (0, 0, (2 << i
) + 10, 2 << i
, 254, -1);
158 for (i
= 1; i
< 8; ++i
)
160 do_test (i
, 2 * i
, (8 << i
) - 1, 8 << i
, 127, 0);
161 do_test (i
, 2 * i
, 8 << i
, 8 << i
, 127, 0);
162 do_test (i
, 2 * i
, (8 << i
) + 100, 8 << i
, 127, 0);
164 do_test (2 * i
, i
, (8 << i
) - 1, 8 << i
, 254, 0);
165 do_test (2 * i
, i
, 8 << i
, 8 << i
, 254, 0);
166 do_test (2 * i
, i
, (8 << i
) + 100, 8 << i
, 254, 0);
168 do_test (i
, 2 * i
, 8 << i
, 8 << i
, 127, 1);
169 do_test (i
, 2 * i
, (8 << i
) + 100, 8 << i
, 127, 1);
171 do_test (2 * i
, i
, 8 << i
, 8 << i
, 254, 1);
172 do_test (2 * i
, i
, (8 << i
) + 100, 8 << i
, 254, 1);
174 do_test (i
, 2 * i
, 8 << i
, 8 << i
, 127, -1);
175 do_test (i
, 2 * i
, (8 << i
) + 100, 8 << i
, 127, -1);
177 do_test (2 * i
, i
, 8 << i
, 8 << i
, 254, -1);
178 do_test (2 * i
, i
, (8 << i
) + 100, 8 << i
, 254, -1);
184 #include <support/test-driver.c>