]>
git.ipfire.org Git - thirdparty/glibc.git/blob - benchtests/bench-strpbrk.c
1 /* Measure strpbrk functions.
2 Copyright (C) 2013-2019 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/>. */
19 #define BIG_CHAR MAX_CHAR
22 # define SMALL_CHAR 127
24 # define SMALL_CHAR 1273
27 #ifndef STRPBRK_RESULT
28 # define STRPBRK_RESULT(s, pos) ((s)[(pos)] ? (s) + (pos) : NULL)
29 # define RES_TYPE CHAR *
32 # define TEST_NAME "strpbrk"
34 # define TEST_NAME "wcspbrk"
36 # include "bench-string.h"
39 # define SIMPLE_STRPBRK simple_strpbrk
40 # define STUPID_STRPBRK stupid_strpbrk
42 # define SIMPLE_STRPBRK simple_wcspbrk
43 # define STUPID_STRPBRK stupid_wcspbrk
46 typedef CHAR
*(*proto_t
) (const CHAR
*, const CHAR
*);
47 CHAR
*SIMPLE_STRPBRK (const CHAR
*, const CHAR
*);
48 CHAR
*STUPID_STRPBRK (const CHAR
*, const CHAR
*);
50 IMPL (STUPID_STRPBRK
, 0)
51 IMPL (SIMPLE_STRPBRK
, 0)
55 SIMPLE_STRPBRK (const CHAR
*s
, const CHAR
*rej
)
60 while ((c
= *s
++) != '\0')
61 for (r
= rej
; *r
!= '\0'; ++r
)
63 return (CHAR
*) s
- 1;
68 STUPID_STRPBRK (const CHAR
*s
, const CHAR
*rej
)
70 size_t ns
= STRLEN (s
), nrej
= STRLEN (rej
);
73 for (i
= 0; i
< ns
; ++i
)
74 for (j
= 0; j
< nrej
; ++j
)
76 return (CHAR
*) s
+ i
;
79 #endif /* !STRPBRK_RESULT */
82 do_one_test (impl_t
*impl
, const CHAR
*s
, const CHAR
*rej
, RES_TYPE exp_res
)
84 RES_TYPE res
= CALL (impl
, s
, rej
);
85 size_t i
, iters
= INNER_LOOP_ITERS
;
86 timing_t start
, stop
, cur
;
90 error (0, 0, "Wrong result in function %s %p %p", impl
->name
,
91 (void *) res
, (void *) exp_res
);
97 for (i
= 0; i
< iters
; ++i
)
103 TIMING_DIFF (cur
, start
, stop
);
105 TIMING_PRINT_MEAN ((double) cur
, (double) iters
);
109 do_test (size_t align
, size_t pos
, size_t len
)
117 if ((align
+ pos
+ 10) * sizeof (CHAR
) >= page_size
|| len
> 240)
120 rej
= (CHAR
*) (buf2
) + (random () & 255);
121 s
= (CHAR
*) (buf1
) + align
;
123 for (i
= 0; i
< len
; ++i
)
125 rej
[i
] = random () & BIG_CHAR
;
127 rej
[i
] = random () & BIG_CHAR
;
129 rej
[i
] = 1 + (random () & SMALL_CHAR
);
132 for (c
= 1; c
<= BIG_CHAR
; ++c
)
133 if (STRCHR (rej
, c
) == NULL
)
136 for (i
= 0; i
< pos
; ++i
)
138 s
[i
] = random () & BIG_CHAR
;
139 if (STRCHR (rej
, s
[i
]))
141 s
[i
] = random () & BIG_CHAR
;
142 if (STRCHR (rej
, s
[i
]))
146 s
[pos
] = rej
[random () % (len
+ 1)];
149 for (i
= pos
+ 1; i
< pos
+ 10; ++i
)
150 s
[i
] = random () & BIG_CHAR
;
153 result
= STRPBRK_RESULT (s
, pos
);
155 printf ("Length %4zd, alignment %2zd, rej len %2zd:", pos
, align
, len
);
157 FOR_EACH_IMPL (impl
, 0)
158 do_one_test (impl
, s
, rej
, result
);
171 FOR_EACH_IMPL (impl
, 0)
172 printf ("\t%s", impl
->name
);
175 for (i
= 0; i
< 32; ++i
)
181 for (i
= 1; i
< 8; ++i
)
183 do_test (0, 16 << i
, 4);
184 do_test (i
, 16 << i
, 4);
187 for (i
= 1; i
< 8; ++i
)
190 for (i
= 0; i
< 64; ++i
)
196 #include <support/test-driver.c>