elf: Refactor process_envvars
[glibc.git] / benchtests / bench-strncasecmp.c
blob051c17d9f78b62d22b4258e7ea04cc15759e2060
1 /* Measure strncasecmp 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/>. */
19 #include <ctype.h>
20 #define TEST_MAIN
21 #define TEST_NAME "strncasecmp"
22 #include "bench-string.h"
23 #include "json-lib.h"
25 typedef int (*proto_t) (const char *, const char *, size_t);
27 IMPL (strncasecmp, 1)
29 static void
30 do_one_test (json_ctx_t *json_ctx, impl_t *impl, const char *s1,
31 const char *s2, size_t n, int exp_result)
33 size_t i, iters = INNER_LOOP_ITERS8;
34 timing_t start, stop, cur;
36 TIMING_NOW (start);
37 for (i = 0; i < iters; ++i)
39 CALL (impl, s1, s2, n);
41 TIMING_NOW (stop);
43 TIMING_DIFF (cur, start, stop);
45 json_element_double (json_ctx, (double) cur / (double) iters);
48 static void
49 do_test (json_ctx_t *json_ctx, size_t align1, size_t align2, size_t n,
50 size_t len, int max_char, int exp_result)
52 size_t i;
53 char *s1, *s2;
55 if (len == 0)
56 return;
58 align1 &= 7;
59 if (align1 + len + 1 >= page_size)
60 return;
62 align2 &= 7;
63 if (align2 + len + 1 >= page_size)
64 return;
66 s1 = (char *) (buf1 + align1);
67 s2 = (char *) (buf2 + align2);
69 for (i = 0; i < len; i++)
71 s1[i] = toupper (1 + 23 * i % max_char);
72 s2[i] = tolower (s1[i]);
75 s1[len] = s2[len] = 0;
76 s1[len + 1] = 23;
77 s2[len + 1] = 24 + exp_result;
78 if ((s2[len - 1] == 'z' && exp_result == -1)
79 || (s2[len - 1] == 'a' && exp_result == 1))
80 s1[len - 1] += exp_result;
81 else
82 s2[len - 1] -= exp_result;
84 json_element_object_begin (json_ctx);
85 json_attr_uint (json_ctx, "length", len);
86 json_attr_uint (json_ctx, "n", n);
87 json_attr_uint (json_ctx, "align1", align1);
88 json_attr_uint (json_ctx, "align2", align2);
89 json_attr_uint (json_ctx, "max_char", max_char);
90 json_array_begin (json_ctx, "timings");
92 FOR_EACH_IMPL (impl, 0)
93 do_one_test (json_ctx, impl, s1, s2, n, exp_result);
95 json_array_end (json_ctx);
96 json_element_object_end (json_ctx);
99 int
100 test_main (void)
102 json_ctx_t json_ctx;
103 size_t i;
105 test_init ();
107 json_init (&json_ctx, 0, stdout);
109 json_document_begin (&json_ctx);
110 json_attr_string (&json_ctx, "timing_type", TIMING_TYPE);
112 json_attr_object_begin (&json_ctx, "functions");
113 json_attr_object_begin (&json_ctx, TEST_NAME);
114 json_attr_string (&json_ctx, "bench-variant", "");
116 json_array_begin (&json_ctx, "ifuncs");
117 FOR_EACH_IMPL (impl, 0)
118 json_element_string (&json_ctx, impl->name);
119 json_array_end (&json_ctx);
121 json_array_begin (&json_ctx, "results");
123 for (i = 1; i < 16; ++i)
125 do_test (&json_ctx, i, i, i - 1, i, 127, 0);
127 do_test (&json_ctx, i, i, i, i, 127, 0);
128 do_test (&json_ctx, i, i, i, i, 127, 1);
129 do_test (&json_ctx, i, i, i, i, 127, -1);
131 do_test (&json_ctx, i, i, i + 1, i, 127, 0);
132 do_test (&json_ctx, i, i, i + 1, i, 127, 1);
133 do_test (&json_ctx, i, i, i + 1, i, 127, -1);
136 for (i = 1; i < 10; ++i)
138 do_test (&json_ctx, 0, 0, (2 << i) - 1, 2 << i, 127, 0);
139 do_test (&json_ctx, 0, 0, 2 << i, 2 << i, 254, 0);
140 do_test (&json_ctx, 0, 0, (2 << i) + 1, 2 << i, 127, 0);
142 do_test (&json_ctx, 0, 0, (2 << i) + 1, 2 << i, 254, 0);
144 do_test (&json_ctx, 0, 0, 2 << i, 2 << i, 127, 1);
145 do_test (&json_ctx, 0, 0, (2 << i) + 10, 2 << i, 127, 1);
147 do_test (&json_ctx, 0, 0, 2 << i, 2 << i, 254, 1);
148 do_test (&json_ctx, 0, 0, (2 << i) + 10, 2 << i, 254, 1);
150 do_test (&json_ctx, 0, 0, 2 << i, 2 << i, 127, -1);
151 do_test (&json_ctx, 0, 0, (2 << i) + 10, 2 << i, 127, -1);
153 do_test (&json_ctx, 0, 0, 2 << i, 2 << i, 254, -1);
154 do_test (&json_ctx, 0, 0, (2 << i) + 10, 2 << i, 254, -1);
157 for (i = 1; i < 8; ++i)
159 do_test (&json_ctx, i, 2 * i, (8 << i) - 1, 8 << i, 127, 0);
160 do_test (&json_ctx, i, 2 * i, 8 << i, 8 << i, 127, 0);
161 do_test (&json_ctx, i, 2 * i, (8 << i) + 100, 8 << i, 127, 0);
163 do_test (&json_ctx, 2 * i, i, (8 << i) - 1, 8 << i, 254, 0);
164 do_test (&json_ctx, 2 * i, i, 8 << i, 8 << i, 254, 0);
165 do_test (&json_ctx, 2 * i, i, (8 << i) + 100, 8 << i, 254, 0);
167 do_test (&json_ctx, i, 2 * i, 8 << i, 8 << i, 127, 1);
168 do_test (&json_ctx, i, 2 * i, (8 << i) + 100, 8 << i, 127, 1);
170 do_test (&json_ctx, 2 * i, i, 8 << i, 8 << i, 254, 1);
171 do_test (&json_ctx, 2 * i, i, (8 << i) + 100, 8 << i, 254, 1);
173 do_test (&json_ctx, i, 2 * i, 8 << i, 8 << i, 127, -1);
174 do_test (&json_ctx, i, 2 * i, (8 << i) + 100, 8 << i, 127, -1);
176 do_test (&json_ctx, 2 * i, i, 8 << i, 8 << i, 254, -1);
177 do_test (&json_ctx, 2 * i, i, (8 << i) + 100, 8 << i, 254, -1);
180 json_array_end (&json_ctx);
181 json_attr_object_end (&json_ctx);
182 json_attr_object_end (&json_ctx);
183 json_document_end (&json_ctx);
185 return ret;
188 #include <support/test-driver.c>