1 /* Measure strspn 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 "strspn"
23 # define TEST_NAME "wcsspn"
25 #include "bench-string.h"
28 #define BIG_CHAR MAX_CHAR
31 # define SMALL_CHAR 127
33 # define SMALL_CHAR 1273
36 typedef size_t (*proto_t
) (const CHAR
*, const CHAR
*);
41 do_one_test (json_ctx_t
*json_ctx
, impl_t
*impl
, const CHAR
*s
,
42 const CHAR
*acc
, size_t exp_res
)
44 size_t res
= CALL (impl
, s
, acc
), i
, iters
= INNER_LOOP_ITERS8
/ CHARBYTES
;
45 timing_t start
, stop
, cur
;
49 error (0, 0, "Wrong result in function %s %p %p", impl
->name
,
50 (void *) res
, (void *) exp_res
);
56 for (i
= 0; i
< iters
; ++i
)
62 TIMING_DIFF (cur
, start
, stop
);
64 json_element_double (json_ctx
, (double)cur
/ (double)iters
);
68 do_test (json_ctx_t
*json_ctx
, size_t align1
, size_t align2
, size_t pos
,
75 if ((align1
+ pos
+ 10) * sizeof (CHAR
) >= page_size
|| len
> 240 || !len
)
77 if ((align2
+ len
) * sizeof (CHAR
) >= page_size
)
80 acc
= (CHAR
*) (buf2
) + align2
;
81 s
= (CHAR
*) (buf1
) + align1
;
83 for (i
= 0; i
< len
; ++i
)
85 acc
[i
] = random () & BIG_CHAR
;
87 acc
[i
] = random () & BIG_CHAR
;
89 acc
[i
] = 1 + (random () & SMALL_CHAR
);
93 for (i
= 0; i
< pos
; ++i
)
94 s
[i
] = acc
[random () % len
];
95 s
[pos
] = random () & BIG_CHAR
;
96 if (STRCHR (acc
, s
[pos
]))
100 for (i
= pos
+ 1; i
< pos
+ 10; ++i
)
101 s
[i
] = random () & BIG_CHAR
;
105 json_element_object_begin (json_ctx
);
106 json_attr_uint (json_ctx
, "len", len
);
107 json_attr_uint (json_ctx
, "pos", pos
);
108 json_attr_uint (json_ctx
, "align1", align1
);
109 json_attr_uint (json_ctx
, "align2", align2
);
110 json_array_begin (json_ctx
, "timings");
112 FOR_EACH_IMPL (impl
, 0)
113 do_one_test (json_ctx
, impl
, s
, acc
, pos
);
115 json_array_end (json_ctx
);
116 json_element_object_end (json_ctx
);
127 json_init (&json_ctx
, 0, stdout
);
129 json_document_begin (&json_ctx
);
130 json_attr_string (&json_ctx
, "timing_type", TIMING_TYPE
);
132 json_attr_object_begin (&json_ctx
, "functions");
133 json_attr_object_begin (&json_ctx
, TEST_NAME
);
134 json_attr_string (&json_ctx
, "bench-variant", "");
136 json_array_begin (&json_ctx
, "ifuncs");
137 FOR_EACH_IMPL (impl
, 0)
138 json_element_string (&json_ctx
, impl
->name
);
139 json_array_end (&json_ctx
);
141 json_array_begin (&json_ctx
, "results");
143 for (i
= 0; i
< 32; ++i
)
145 do_test (&json_ctx
, 0, 0, 512, i
);
146 do_test (&json_ctx
, i
, 0, 512, i
);
147 do_test (&json_ctx
, 0, i
, 512, i
);
148 do_test (&json_ctx
, i
, i
, 512, i
);
151 for (i
= 1; i
< 8; ++i
)
153 do_test (&json_ctx
, 0, 0, 16 << i
, 4);
154 do_test (&json_ctx
, i
, 0, 16 << i
, 4);
155 do_test (&json_ctx
, 0, i
, 16 << i
, 4);
156 do_test (&json_ctx
, i
, i
, 16 << i
, 4);
159 for (i
= 1; i
< 8; ++i
)
161 do_test (&json_ctx
, i
, 0, 64, 10);
162 do_test (&json_ctx
, i
, i
, 64, 10);
165 for (i
= 0; i
< 64; ++i
)
167 do_test (&json_ctx
, 0, 0, i
, 6);
168 do_test (&json_ctx
, 0, i
, i
, 6);
171 json_array_end (&json_ctx
);
172 json_attr_object_end (&json_ctx
);
173 json_attr_object_end (&json_ctx
);
174 json_document_end (&json_ctx
);
179 #include <support/test-driver.c>