1 /* Measure strpbrk functions.
2 Copyright (C) 2013 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 #ifndef STRPBRK_RESULT
20 # define STRPBRK_RESULT(s, pos) ((s)[(pos)] ? (s) + (pos) : NULL)
21 # define RES_TYPE char *
23 # define TEST_NAME "strpbrk"
24 # include "bench-string.h"
26 typedef char *(*proto_t
) (const char *, const char *);
27 char *simple_strpbrk (const char *, const char *);
28 char *stupid_strpbrk (const char *, const char *);
30 IMPL (stupid_strpbrk
, 0)
31 IMPL (simple_strpbrk
, 0)
35 simple_strpbrk (const char *s
, const char *rej
)
40 while ((c
= *s
++) != '\0')
41 for (r
= rej
; *r
!= '\0'; ++r
)
43 return (char *) s
- 1;
48 stupid_strpbrk (const char *s
, const char *rej
)
50 size_t ns
= strlen (s
), nrej
= strlen (rej
);
53 for (i
= 0; i
< ns
; ++i
)
54 for (j
= 0; j
< nrej
; ++j
)
56 return (char *) s
+ i
;
62 do_one_test (impl_t
*impl
, const char *s
, const char *rej
, RES_TYPE exp_res
)
64 RES_TYPE res
= CALL (impl
, s
, rej
);
67 error (0, 0, "Wrong result in function %s %p %p", impl
->name
,
68 (void *) res
, (void *) exp_res
);
75 hp_timing_t start
__attribute ((unused
));
76 hp_timing_t stop
__attribute ((unused
));
77 hp_timing_t best_time
= ~ (hp_timing_t
) 0;
80 for (i
= 0; i
< 32; ++i
)
82 HP_TIMING_NOW (start
);
85 HP_TIMING_BEST (best_time
, start
, stop
);
88 printf ("\t%zd", (size_t) best_time
);
93 do_test (size_t align
, size_t pos
, size_t len
)
101 if (align
+ pos
+ 10 >= 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 () & 255;
111 rej
[i
] = random () & 255;
113 rej
[i
] = 1 + (random () & 127);
116 for (c
= 1; c
<= 255; ++c
)
117 if (strchr (rej
, c
) == NULL
)
120 for (i
= 0; i
< pos
; ++i
)
122 s
[i
] = random () & 255;
123 if (strchr (rej
, s
[i
]))
125 s
[i
] = random () & 255;
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 () & 255;
137 result
= STRPBRK_RESULT (s
, pos
);
140 printf ("Length %4zd, alignment %2zd, rej len %2zd:", pos
, align
, len
);
142 FOR_EACH_IMPL (impl
, 0)
143 do_one_test (impl
, s
, rej
, result
);
157 FOR_EACH_IMPL (impl
, 0)
158 printf ("\t%s", impl
->name
);
161 for (i
= 0; i
< 32; ++i
)
167 for (i
= 1; i
< 8; ++i
)
169 do_test (0, 16 << i
, 4);
170 do_test (i
, 16 << i
, 4);
173 for (i
= 1; i
< 8; ++i
)
176 for (i
= 0; i
< 64; ++i
)
182 #include "../test-skeleton.c"