1 /* Measure strtok functions.
2 Copyright (C) 2013-2014 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/>. */
20 #define TEST_NAME "strtok"
21 #include "bench-string.h"
24 simple_strtok (char *s1
, char *s2
)
30 size_t s2len
= strlen (s2
);
34 if (s1
== NULL
|| *s1
== '\0')
44 for (j
= 0; j
< s2len
; j
++)
65 for (j
= 0; j
< s2len
; j
++)
80 typedef char *(*proto_t
) (const char *, const char *);
82 IMPL (simple_strtok
, 0)
86 do_one_test (impl_t
* impl
, const char *s1
, const char *s2
)
88 size_t i
, iters
= INNER_LOOP_ITERS
;
89 timing_t start
, stop
, cur
;
91 for (i
= 0; i
< iters
; ++i
)
94 CALL (impl
, NULL
, s2
);
95 CALL (impl
, NULL
, s2
);
99 TIMING_DIFF (cur
, start
, stop
);
101 TIMING_PRINT_MEAN ((double) cur
, (double) iters
);
107 do_test (size_t align1
, size_t align2
, size_t len1
, size_t len2
, int fail
)
109 char *s2
= (char *) (buf2
+ align2
);
110 static const char d
[] = "1234567890abcdef";
111 #define dl (sizeof (d) - 1)
113 for (size_t l
= len2
; l
> 0; l
= l
> dl
? l
- dl
: 0)
115 size_t t
= l
> dl
? dl
: l
;
116 ss2
= mempcpy (ss2
, d
, t
);
120 printf ("Length %4zd/%zd, alignment %2zd/%2zd, %s:",
121 len1
, len2
, align1
, align2
, fail
? "fail" : "found");
123 FOR_EACH_IMPL (impl
, 0)
125 char *s1
= (char *) (buf1
+ align1
);
129 for (size_t l
= len1
; l
> 0; l
= l
> dl
? l
- dl
: 0)
131 size_t t
= l
> dl
? dl
: l
;
133 ++ss1
[len2
> 7 ? 7 : len2
- 1];
139 memset (s1
, '0', len1
);
140 memcpy (s1
+ (len1
- len2
) - 2, s2
, len2
);
141 if ((len1
/ len2
) > 4)
142 memcpy (s1
+ (len1
- len2
) - (3 * len2
), s2
, len2
);
145 do_one_test (impl
, s1
, s2
);
156 FOR_EACH_IMPL (impl
, 0)
157 printf ("\t%s", impl
->name
);
160 for (size_t klen
= 2; klen
< 32; ++klen
)
161 for (size_t hlen
= 2 * klen
; hlen
< 16 * klen
; hlen
+= klen
)
163 do_test (0, 0, hlen
, klen
, 0);
164 do_test (0, 0, hlen
, klen
, 1);
165 do_test (0, 3, hlen
, klen
, 0);
166 do_test (0, 3, hlen
, klen
, 1);
167 do_test (0, 9, hlen
, klen
, 0);
168 do_test (0, 9, hlen
, klen
, 1);
169 do_test (0, 15, hlen
, klen
, 0);
170 do_test (0, 15, hlen
, klen
, 1);
172 do_test (3, 0, hlen
, klen
, 0);
173 do_test (3, 0, hlen
, klen
, 1);
174 do_test (3, 3, hlen
, klen
, 0);
175 do_test (3, 3, hlen
, klen
, 1);
176 do_test (3, 9, hlen
, klen
, 0);
177 do_test (3, 9, hlen
, klen
, 1);
178 do_test (3, 15, hlen
, klen
, 0);
179 do_test (3, 15, hlen
, klen
, 1);
181 do_test (9, 0, hlen
, klen
, 0);
182 do_test (9, 0, hlen
, klen
, 1);
183 do_test (9, 3, hlen
, klen
, 0);
184 do_test (9, 3, hlen
, klen
, 1);
185 do_test (9, 9, hlen
, klen
, 0);
186 do_test (9, 9, hlen
, klen
, 1);
187 do_test (9, 15, hlen
, klen
, 0);
188 do_test (9, 15, hlen
, klen
, 1);
190 do_test (15, 0, hlen
, klen
, 0);
191 do_test (15, 0, hlen
, klen
, 1);
192 do_test (15, 3, hlen
, klen
, 0);
193 do_test (15, 3, hlen
, klen
, 1);
194 do_test (15, 9, hlen
, klen
, 0);
195 do_test (15, 9, hlen
, klen
, 1);
196 do_test (15, 15, hlen
, klen
, 0);
197 do_test (15, 15, hlen
, klen
, 1);
199 do_test (0, 0, page_size
- 1, 16, 0);
200 do_test (0, 0, page_size
- 1, 16, 1);
205 #include "../test-skeleton.c"