mirror of
https://sourceware.org/git/glibc.git
synced 2024-11-27 03:33:33 +08:00
Benchtests: Remove simple_strcspn/strpbrk/strsep
Remove simple_strcspn/strpbrk/strsep which are significantly slower than the generic implementations. Also remove oldstrsep and oldstrtok since they are practically identical to the generic implementation. Adjust iteration count to reduce benchmark time. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
This commit is contained in:
parent
b0e02d5b6d
commit
5de1508803
@ -26,29 +26,8 @@
|
||||
#endif /* WIDE */
|
||||
#include "bench-string.h"
|
||||
|
||||
#ifndef WIDE
|
||||
# define SIMPLE_STRCSPN simple_strcspn
|
||||
#else
|
||||
# define SIMPLE_STRCSPN simple_wcscspn
|
||||
#endif /* WIDE */
|
||||
|
||||
typedef size_t (*proto_t) (const CHAR *, const CHAR *);
|
||||
size_t SIMPLE_STRCSPN (const CHAR *, const CHAR *);
|
||||
|
||||
IMPL (SIMPLE_STRCSPN, 0)
|
||||
IMPL (STRCSPN, 1)
|
||||
|
||||
size_t
|
||||
SIMPLE_STRCSPN (const CHAR *s, const CHAR *rej)
|
||||
{
|
||||
const CHAR *r, *str = s;
|
||||
CHAR c;
|
||||
|
||||
while ((c = *s++) != '\0')
|
||||
for (r = rej; *r != '\0'; ++r)
|
||||
if (*r == c)
|
||||
return s - str - 1;
|
||||
return s - str - 1;
|
||||
}
|
||||
|
||||
#include "bench-strpbrk.c"
|
||||
|
@ -35,31 +35,10 @@
|
||||
# endif /* WIDE */
|
||||
# include "bench-string.h"
|
||||
|
||||
# ifndef WIDE
|
||||
# define SIMPLE_STRPBRK simple_strpbrk
|
||||
# else
|
||||
# define SIMPLE_STRPBRK simple_wcspbrk
|
||||
# endif /* WIDE */
|
||||
|
||||
typedef CHAR *(*proto_t) (const CHAR *, const CHAR *);
|
||||
CHAR *SIMPLE_STRPBRK (const CHAR *, const CHAR *);
|
||||
|
||||
IMPL (SIMPLE_STRPBRK, 0)
|
||||
IMPL (STRPBRK, 1)
|
||||
|
||||
CHAR *
|
||||
SIMPLE_STRPBRK (const CHAR *s, const CHAR *rej)
|
||||
{
|
||||
const CHAR *r;
|
||||
CHAR c;
|
||||
|
||||
while ((c = *s++) != '\0')
|
||||
for (r = rej; *r != '\0'; ++r)
|
||||
if (*r == c)
|
||||
return (CHAR *) s - 1;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#endif /* !STRPBRK_RESULT */
|
||||
|
||||
#include "json-lib.h"
|
||||
@ -69,7 +48,7 @@ do_one_test (json_ctx_t *json_ctx, impl_t *impl, const CHAR *s,
|
||||
const CHAR *rej, RES_TYPE exp_res)
|
||||
{
|
||||
RES_TYPE res = CALL (impl, s, rej);
|
||||
size_t i, iters = INNER_LOOP_ITERS;
|
||||
size_t i, iters = INNER_LOOP_ITERS8 / CHARBYTES;
|
||||
timing_t start, stop, cur;
|
||||
|
||||
if (res != exp_res)
|
||||
|
@ -20,90 +20,14 @@
|
||||
#define TEST_NAME "strsep"
|
||||
#include "bench-string.h"
|
||||
|
||||
char *
|
||||
simple_strsep (char **s1, char *s2)
|
||||
{
|
||||
char *begin;
|
||||
char *s;
|
||||
size_t j = 0;
|
||||
|
||||
begin = *s1;
|
||||
s = begin;
|
||||
if (begin == NULL)
|
||||
return NULL;
|
||||
ssize_t s2len = strlen (s2);
|
||||
while (*s)
|
||||
{
|
||||
for (j = 0; j < s2len; j++)
|
||||
{
|
||||
if (*s == s2[j])
|
||||
{
|
||||
s[0] = '\0';
|
||||
*s1 = s + 1;
|
||||
return begin;
|
||||
}
|
||||
}
|
||||
s++;
|
||||
}
|
||||
*s1 = NULL;
|
||||
return begin;
|
||||
}
|
||||
|
||||
char *
|
||||
oldstrsep (char **stringp, const char *delim)
|
||||
{
|
||||
char *begin, *end;
|
||||
|
||||
begin = *stringp;
|
||||
if (begin == NULL)
|
||||
return NULL;
|
||||
|
||||
/* A frequent case is when the delimiter string contains only one
|
||||
character. Here we don't need to call the expensive `strpbrk'
|
||||
function and instead work using `strchr'. */
|
||||
if (delim[0] == '\0' || delim[1] == '\0')
|
||||
{
|
||||
char ch = delim[0];
|
||||
|
||||
if (ch == '\0')
|
||||
end = NULL;
|
||||
else
|
||||
{
|
||||
if (*begin == ch)
|
||||
end = begin;
|
||||
else if (*begin == '\0')
|
||||
end = NULL;
|
||||
else
|
||||
end = strchr (begin + 1, ch);
|
||||
}
|
||||
}
|
||||
else
|
||||
/* Find the end of the token. */
|
||||
end = strpbrk (begin, delim);
|
||||
|
||||
if (end)
|
||||
{
|
||||
/* Terminate the token and set *STRINGP past NUL character. */
|
||||
*end++ = '\0';
|
||||
*stringp = end;
|
||||
}
|
||||
else
|
||||
/* No more delimiters; this is the last token. */
|
||||
*stringp = NULL;
|
||||
|
||||
return begin;
|
||||
}
|
||||
|
||||
typedef char *(*proto_t) (const char **, const char *);
|
||||
|
||||
IMPL (simple_strsep, 0)
|
||||
IMPL (strsep, 1)
|
||||
IMPL (oldstrsep, 2)
|
||||
|
||||
static void
|
||||
do_one_test (impl_t * impl, const char *s1, const char *s2)
|
||||
{
|
||||
size_t i, iters = INNER_LOOP_ITERS_SMALL;
|
||||
size_t i, iters = INNER_LOOP_ITERS;
|
||||
timing_t start, stop, cur;
|
||||
|
||||
TIMING_NOW (start);
|
||||
|
@ -28,41 +28,20 @@
|
||||
#define BIG_CHAR MAX_CHAR
|
||||
|
||||
#ifndef WIDE
|
||||
# define SIMPLE_STRSPN simple_strspn
|
||||
# define SMALL_CHAR 127
|
||||
#else
|
||||
# define SIMPLE_STRSPN simple_wcsspn
|
||||
# define SMALL_CHAR 1273
|
||||
#endif /* WIDE */
|
||||
|
||||
typedef size_t (*proto_t) (const CHAR *, const CHAR *);
|
||||
size_t SIMPLE_STRSPN (const CHAR *, const CHAR *);
|
||||
|
||||
IMPL (SIMPLE_STRSPN, 0)
|
||||
IMPL (STRSPN, 1)
|
||||
|
||||
size_t
|
||||
SIMPLE_STRSPN (const CHAR *s, const CHAR *acc)
|
||||
{
|
||||
const CHAR *r, *str = s;
|
||||
CHAR c;
|
||||
|
||||
while ((c = *s++) != '\0')
|
||||
{
|
||||
for (r = acc; *r != '\0'; ++r)
|
||||
if (*r == c)
|
||||
break;
|
||||
if (*r == '\0')
|
||||
return s - str - 1;
|
||||
}
|
||||
return s - str - 1;
|
||||
}
|
||||
|
||||
static void
|
||||
do_one_test (json_ctx_t *json_ctx, impl_t *impl, const CHAR *s,
|
||||
const CHAR *acc, size_t exp_res)
|
||||
{
|
||||
size_t res = CALL (impl, s, acc), i, iters = INNER_LOOP_ITERS;
|
||||
size_t res = CALL (impl, s, acc), i, iters = INNER_LOOP_ITERS8 / CHARBYTES;
|
||||
timing_t start, stop, cur;
|
||||
|
||||
if (res != exp_res)
|
||||
|
@ -20,47 +20,14 @@
|
||||
#define TEST_NAME "strtok"
|
||||
#include "bench-string.h"
|
||||
|
||||
char *
|
||||
oldstrtok (char *s, const char *delim)
|
||||
{
|
||||
static char *olds;
|
||||
char *token;
|
||||
|
||||
if (s == NULL)
|
||||
s = olds;
|
||||
|
||||
/* Scan leading delimiters. */
|
||||
s += strspn (s, delim);
|
||||
if (*s == '\0')
|
||||
{
|
||||
olds = s;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Find the end of the token. */
|
||||
token = s;
|
||||
s = strpbrk (token, delim);
|
||||
if (s == NULL)
|
||||
/* This token finishes the string. */
|
||||
olds = strchr (token, '\0');
|
||||
else
|
||||
{
|
||||
/* Terminate the token and make OLDS point past it. */
|
||||
*s = '\0';
|
||||
olds = s + 1;
|
||||
}
|
||||
return token;
|
||||
}
|
||||
|
||||
typedef char *(*proto_t) (const char *, const char *);
|
||||
|
||||
IMPL (oldstrtok, 0)
|
||||
IMPL (strtok, 1)
|
||||
|
||||
static void
|
||||
do_one_test (impl_t * impl, const char *s1, const char *s2)
|
||||
{
|
||||
size_t i, iters = INNER_LOOP_ITERS_SMALL;
|
||||
size_t i, iters = INNER_LOOP_ITERS_MEDIUM;
|
||||
timing_t start, stop, cur;
|
||||
TIMING_NOW (start);
|
||||
for (i = 0; i < iters; ++i)
|
||||
@ -74,7 +41,6 @@ do_one_test (impl_t * impl, const char *s1, const char *s2)
|
||||
TIMING_DIFF (cur, start, stop);
|
||||
|
||||
TIMING_PRINT_MEAN ((double) cur, (double) iters);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user