1 /* Measure strsep functions.
2 Copyright (C) 2013-2024 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/>. */
20 #define TEST_NAME "strsep"
21 #include "bench-string.h"
23 typedef char *(*proto_t
) (const char **, const char *);
28 do_one_test (impl_t
* impl
, const char *s1
, const char *s2
)
30 size_t i
, iters
= INNER_LOOP_ITERS
;
31 timing_t start
, stop
, cur
;
34 for (i
= 0; i
< iters
; ++i
)
37 CALL (impl
, &s1a
, s2
);
39 ((char*)s1a
)[-1] = '1';
43 TIMING_DIFF (cur
, start
, stop
);
45 TIMING_PRINT_MEAN ((double) cur
, (double) iters
);
49 do_test (size_t align1
, size_t align2
, size_t len1
, size_t len2
, int fail
)
51 char *s2
= (char *) (buf2
+ align2
);
53 /* Search for a delimiter in a string containing mostly '0', so don't
54 use '0' as a delimiter. */
55 static const char d
[] = "123456789abcdefg";
56 #define dl (sizeof (d) - 1)
58 for (size_t l
= len2
; l
> 0; l
= l
> dl
? l
- dl
: 0)
60 size_t t
= l
> dl
? dl
: l
;
61 ss2
= mempcpy (ss2
, d
, t
);
65 printf ("Length %4zd/%zd, alignment %2zd/%2zd, %s:",
66 len1
, len2
, align1
, align2
, fail
? "fail" : "found");
68 FOR_EACH_IMPL (impl
, 0)
70 char *s1
= (char *) (buf1
+ align1
);
71 memset (s1
, '0', len1
);
75 do_one_test (impl
, s1
, s2
);
86 FOR_EACH_IMPL (impl
, 0)
87 printf ("\t%s", impl
->name
);
90 for (size_t klen
= 2; klen
< 32; ++klen
)
91 for (size_t hlen
= 4 * klen
; hlen
< 8 * klen
; hlen
+= klen
)
93 do_test (0, 0, hlen
, klen
, 0);
94 do_test (0, 0, hlen
, klen
, 1);
95 do_test (0, 3, hlen
, klen
, 0);
96 do_test (0, 3, hlen
, klen
, 1);
97 do_test (0, 9, hlen
, klen
, 0);
98 do_test (0, 9, hlen
, klen
, 1);
99 do_test (0, 15, hlen
, klen
, 0);
100 do_test (0, 15, hlen
, klen
, 1);
102 do_test (3, 0, hlen
, klen
, 0);
103 do_test (3, 0, hlen
, klen
, 1);
104 do_test (3, 3, hlen
, klen
, 0);
105 do_test (3, 3, hlen
, klen
, 1);
106 do_test (3, 9, hlen
, klen
, 0);
107 do_test (3, 9, hlen
, klen
, 1);
108 do_test (3, 15, hlen
, klen
, 0);
109 do_test (3, 15, hlen
, klen
, 1);
111 do_test (9, 0, hlen
, klen
, 0);
112 do_test (9, 0, hlen
, klen
, 1);
113 do_test (9, 3, hlen
, klen
, 0);
114 do_test (9, 3, hlen
, klen
, 1);
115 do_test (9, 9, hlen
, klen
, 0);
116 do_test (9, 9, hlen
, klen
, 1);
117 do_test (9, 15, hlen
, klen
, 0);
118 do_test (9, 15, hlen
, klen
, 1);
120 do_test (15, 0, hlen
, klen
, 0);
121 do_test (15, 0, hlen
, klen
, 1);
122 do_test (15, 3, hlen
, klen
, 0);
123 do_test (15, 3, hlen
, klen
, 1);
124 do_test (15, 9, hlen
, klen
, 0);
125 do_test (15, 9, hlen
, klen
, 1);
126 do_test (15, 15, hlen
, klen
, 0);
127 do_test (15, 15, hlen
, klen
, 1);
129 do_test (0, 0, page_size
- 1, 16, 0);
130 do_test (0, 0, page_size
- 1, 16, 1);
135 #include <support/test-driver.c>