]>
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
41 # define SIMPLE_STRPBRK simple_wcspbrk
44 typedef CHAR
*(*proto_t
) (const CHAR
*, const CHAR
*);
45 CHAR
*SIMPLE_STRPBRK (const CHAR
*, const CHAR
*);
47 IMPL (SIMPLE_STRPBRK
, 0)
51 SIMPLE_STRPBRK (const CHAR
*s
, const CHAR
*rej
)
56 while ((c
= *s
++) != '\0')
57 for (r
= rej
; *r
!= '\0'; ++r
)
59 return (CHAR
*) s
- 1;
63 #endif /* !STRPBRK_RESULT */
66 do_one_test (impl_t
*impl
, const CHAR
*s
, const CHAR
*rej
, RES_TYPE exp_res
)
68 RES_TYPE res
= CALL (impl
, s
, rej
);
69 size_t i
, iters
= INNER_LOOP_ITERS_MEDIUM
;
70 timing_t start
, stop
, cur
;
74 error (0, 0, "Wrong result in function %s %p %p", impl
->name
,
75 (void *) res
, (void *) exp_res
);
81 for (i
= 0; i
< iters
; ++i
)
87 TIMING_DIFF (cur
, start
, stop
);
89 TIMING_PRINT_MEAN ((double) cur
, (double) iters
);
93 do_test (size_t align
, size_t pos
, size_t len
)
101 if ((align
+ pos
+ 10) * sizeof (CHAR
) >= page_size
|| len
> 240)
104 rej
= (CHAR
*) (buf2
) + (random () & 255);
105 s
= (CHAR
*) (buf1
) + align
;
107 for (i
= 0; i
< len
; ++i
)
109 rej
[i
] = random () & BIG_CHAR
;
111 rej
[i
] = random () & BIG_CHAR
;
113 rej
[i
] = 1 + (random () & SMALL_CHAR
);
116 for (c
= 1; c
<= BIG_CHAR
; ++c
)
117 if (STRCHR (rej
, c
) == NULL
)
120 for (i
= 0; i
< pos
; ++i
)
122 s
[i
] = random () & BIG_CHAR
;
123 if (STRCHR (rej
, s
[i
]))
125 s
[i
] = random () & BIG_CHAR
;
126 if (STRCHR (rej
, s
[i
]))
130 s
[pos
] = rej
[random () % (len
+ 1)];
133 for (i
= pos
+ 1; i
< pos
+ 10; ++i
)
134 s
[i
] = random () & BIG_CHAR
;
137 result
= STRPBRK_RESULT (s
, pos
);
139 printf ("Length %4zd, alignment %2zd, rej len %2zd:", pos
, align
, len
);
141 FOR_EACH_IMPL (impl
, 0)
142 do_one_test (impl
, s
, rej
, result
);
155 FOR_EACH_IMPL (impl
, 0)
156 printf ("\t%s", impl
->name
);
159 for (i
= 0; i
< 32; ++i
)
165 for (i
= 1; i
< 8; ++i
)
167 do_test (0, 16 << i
, 4);
168 do_test (i
, 16 << i
, 4);
171 for (i
= 1; i
< 8; ++i
)
174 for (i
= 0; i
< 64; ++i
)
180 #include <support/test-driver.c>