1 /* Measure strpbrk functions.
2 Copyright (C) 2013-2018 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 STRLEN strlen
22 # define STRCHR strchr
23 # define BIG_CHAR CHAR_MAX
24 # define SMALL_CHAR 127
28 # define STRLEN wcslen
29 # define STRCHR wcschr
30 # define BIG_CHAR WCHAR_MAX
31 # define SMALL_CHAR 1273
34 #ifndef STRPBRK_RESULT
35 # define STRPBRK_RESULT(s, pos) ((s)[(pos)] ? (s) + (pos) : NULL)
36 # define RES_TYPE CHAR *
39 # define TEST_NAME "strpbrk"
41 # define TEST_NAME "wcspbrk"
43 # include "bench-string.h"
46 # define STRPBRK strpbrk
47 # define SIMPLE_STRPBRK simple_strpbrk
48 # define STUPID_STRPBRK stupid_strpbrk
51 # define STRPBRK wcspbrk
52 # define SIMPLE_STRPBRK simple_wcspbrk
53 # define STUPID_STRPBRK stupid_wcspbrk
56 typedef CHAR
*(*proto_t
) (const CHAR
*, const CHAR
*);
57 CHAR
*SIMPLE_STRPBRK (const CHAR
*, const CHAR
*);
58 CHAR
*STUPID_STRPBRK (const CHAR
*, const CHAR
*);
60 IMPL (STUPID_STRPBRK
, 0)
61 IMPL (SIMPLE_STRPBRK
, 0)
65 SIMPLE_STRPBRK (const CHAR
*s
, const CHAR
*rej
)
70 while ((c
= *s
++) != '\0')
71 for (r
= rej
; *r
!= '\0'; ++r
)
73 return (CHAR
*) s
- 1;
78 STUPID_STRPBRK (const CHAR
*s
, const CHAR
*rej
)
80 size_t ns
= STRLEN (s
), nrej
= STRLEN (rej
);
83 for (i
= 0; i
< ns
; ++i
)
84 for (j
= 0; j
< nrej
; ++j
)
86 return (CHAR
*) s
+ i
;
89 #endif /* !STRPBRK_RESULT */
92 do_one_test (impl_t
*impl
, const CHAR
*s
, const CHAR
*rej
, RES_TYPE exp_res
)
94 RES_TYPE res
= CALL (impl
, s
, rej
);
95 size_t i
, iters
= INNER_LOOP_ITERS
;
96 timing_t start
, stop
, cur
;
100 error (0, 0, "Wrong result in function %s %p %p", impl
->name
,
101 (void *) res
, (void *) exp_res
);
107 for (i
= 0; i
< iters
; ++i
)
113 TIMING_DIFF (cur
, start
, stop
);
115 TIMING_PRINT_MEAN ((double) cur
, (double) iters
);
119 do_test (size_t align
, size_t pos
, size_t len
)
127 if ((align
+ pos
+ 10) * sizeof (CHAR
) >= page_size
|| len
> 240)
130 rej
= (CHAR
*) (buf2
) + (random () & 255);
131 s
= (CHAR
*) (buf1
) + align
;
133 for (i
= 0; i
< len
; ++i
)
135 rej
[i
] = random () & BIG_CHAR
;
137 rej
[i
] = random () & BIG_CHAR
;
139 rej
[i
] = 1 + (random () & SMALL_CHAR
);
142 for (c
= 1; c
<= BIG_CHAR
; ++c
)
143 if (STRCHR (rej
, c
) == NULL
)
146 for (i
= 0; i
< pos
; ++i
)
148 s
[i
] = random () & BIG_CHAR
;
149 if (STRCHR (rej
, s
[i
]))
151 s
[i
] = random () & BIG_CHAR
;
152 if (STRCHR (rej
, s
[i
]))
156 s
[pos
] = rej
[random () % (len
+ 1)];
159 for (i
= pos
+ 1; i
< pos
+ 10; ++i
)
160 s
[i
] = random () & BIG_CHAR
;
163 result
= STRPBRK_RESULT (s
, pos
);
165 printf ("Length %4zd, alignment %2zd, rej len %2zd:", pos
, align
, len
);
167 FOR_EACH_IMPL (impl
, 0)
168 do_one_test (impl
, s
, rej
, result
);
181 FOR_EACH_IMPL (impl
, 0)
182 printf ("\t%s", impl
->name
);
185 for (i
= 0; i
< 32; ++i
)
191 for (i
= 1; i
< 8; ++i
)
193 do_test (0, 16 << i
, 4);
194 do_test (i
, 16 << i
, 4);
197 for (i
= 1; i
< 8; ++i
)
200 for (i
= 0; i
< 64; ++i
)
206 #include <support/test-driver.c>