mirror of
git://sourceware.org/git/glibc.git
synced 2025-03-06 20:58:33 +01:00
Benchtests: Remove simple_mem(r)chr
Instead of benchmarking slow byte oriented loops, include the optimized generic memchr/memrchr implementation. Adjust iteration count to reduce benchmark time. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
This commit is contained in:
parent
73a284f618
commit
dcfcb8e392
2 changed files with 26 additions and 30 deletions
|
@ -16,6 +16,8 @@
|
||||||
License along with the GNU C Library; if not, see
|
License along with the GNU C Library; if not, see
|
||||||
<https://www.gnu.org/licenses/>. */
|
<https://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
|
#include "json-lib.h"
|
||||||
|
|
||||||
#ifndef WIDE
|
#ifndef WIDE
|
||||||
# define SMALL_CHAR 127
|
# define SMALL_CHAR 127
|
||||||
#else
|
#else
|
||||||
|
@ -31,35 +33,25 @@
|
||||||
# endif /* WIDE */
|
# endif /* WIDE */
|
||||||
# include "bench-string.h"
|
# include "bench-string.h"
|
||||||
|
|
||||||
# ifndef WIDE
|
typedef void *(*proto_t) (const void *, int, size_t);
|
||||||
# define SIMPLE_MEMCHR simple_memchr
|
|
||||||
# else
|
|
||||||
# define SIMPLE_MEMCHR simple_wmemchr
|
|
||||||
# endif /* WIDE */
|
|
||||||
|
|
||||||
typedef CHAR *(*proto_t) (const CHAR *, int, size_t);
|
void *
|
||||||
CHAR *SIMPLE_MEMCHR (const CHAR *, int, size_t);
|
generic_memchr (const void *, int, size_t);
|
||||||
|
|
||||||
IMPL (SIMPLE_MEMCHR, 0)
|
|
||||||
IMPL (MEMCHR, 1)
|
IMPL (MEMCHR, 1)
|
||||||
|
|
||||||
CHAR *
|
# ifndef WIDE
|
||||||
SIMPLE_MEMCHR (const CHAR *s, int c, size_t n)
|
IMPL (generic_memchr, 0)
|
||||||
{
|
# endif
|
||||||
while (n--)
|
|
||||||
if (*s++ == (CHAR) c)
|
|
||||||
return (CHAR *) s - 1;
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
#endif /* !USE_AS_MEMRCHR */
|
#endif /* !USE_AS_MEMRCHR */
|
||||||
|
|
||||||
#include "json-lib.h"
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
do_one_test (json_ctx_t *json_ctx, impl_t *impl, const CHAR *s, int c,
|
do_one_test (json_ctx_t *json_ctx, impl_t *impl, const CHAR *s, int c,
|
||||||
size_t n)
|
size_t n)
|
||||||
{
|
{
|
||||||
size_t i, iters = INNER_LOOP_ITERS_LARGE;
|
size_t i, iters = INNER_LOOP_ITERS;
|
||||||
timing_t start, stop, cur;
|
timing_t start, stop, cur;
|
||||||
|
|
||||||
TIMING_NOW (start);
|
TIMING_NOW (start);
|
||||||
|
@ -250,3 +242,15 @@ test_main (void)
|
||||||
}
|
}
|
||||||
|
|
||||||
#include <support/test-driver.c>
|
#include <support/test-driver.c>
|
||||||
|
|
||||||
|
#ifndef WIDE
|
||||||
|
# ifndef USE_AS_MEMRCHR
|
||||||
|
# undef MEMCHR
|
||||||
|
# define MEMCHR generic_memchr
|
||||||
|
# include <string/memchr.c>
|
||||||
|
# else
|
||||||
|
# undef MEMRCHR
|
||||||
|
# define MEMRCHR generic_memrchr
|
||||||
|
# include <string/memrchr.c>
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
|
@ -21,20 +21,12 @@
|
||||||
#include "bench-string.h"
|
#include "bench-string.h"
|
||||||
|
|
||||||
typedef char *(*proto_t) (const char *, int, size_t);
|
typedef char *(*proto_t) (const char *, int, size_t);
|
||||||
char *simple_memrchr (const char *, int, size_t);
|
|
||||||
|
|
||||||
IMPL (simple_memrchr, 0)
|
void *
|
||||||
|
generic_memrchr (const void *, int, size_t);
|
||||||
|
|
||||||
IMPL (memrchr, 1)
|
IMPL (memrchr, 1)
|
||||||
|
IMPL (generic_memrchr, 0)
|
||||||
char *
|
|
||||||
simple_memrchr (const char *s, int c, size_t n)
|
|
||||||
{
|
|
||||||
s = s + n;
|
|
||||||
while (n--)
|
|
||||||
if (*--s == (char) c)
|
|
||||||
return (char *) s;
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
#define USE_AS_MEMRCHR
|
#define USE_AS_MEMRCHR
|
||||||
#include "bench-memchr.c"
|
#include "bench-memchr.c"
|
||||||
|
|
Loading…
Add table
Reference in a new issue