mirror of git://sourceware.org/git/glibc.git
Improve string benchtests
Replace slow byte-oriented tests in several string benchmarks with the generic implementations from the string/ directory so the comparisons are more realistic and useful. * benchtests/bench-stpcpy.c (SIMPLE_STPCPY): Remove function. (generic_stpcpy): New function. * benchtests/bench-stpncpy.c (SIMPLE_STPNCPY): Remove function. (generic_stpncpy): New function. * benchtests/bench-strcat.c (SIMPLE_STRCAT): Remove function. (generic_strcat): New function. * benchtests/bench-strcpy.c (SIMPLE_STRCPY): Remove function. (generic_strcpy): New function. * benchtests/bench-strncat.c (SIMPLE_STRNCAT): Remove function. (STUPID_STRNCAT): Remove function. (generic_strncat): New function. * benchtests/bench-strncpy.c (SIMPLE_STRNCPY): Remove function. (STUPID_STRNCPY): Remove function. (generic_strncpy): New function. * benchtests/bench-strnlen.c (SIMPLE_STRNLEN): Remove function. (generic_strnlen): New function. (memchr_strnlen): New function. * benchtests/bench-strlen.c (generic_strlen): Define for WIDE. (memchr_strlen): Likewise.
This commit is contained in:
parent
93eebae516
commit
648279f4af
22
ChangeLog
22
ChangeLog
|
@ -1,3 +1,25 @@
|
||||||
|
2019-04-09 Wilco Dijkstra <wdijkstr@arm.com>
|
||||||
|
|
||||||
|
* benchtests/bench-stpcpy.c (SIMPLE_STPCPY): Remove function.
|
||||||
|
(generic_stpcpy): New function.
|
||||||
|
* benchtests/bench-stpncpy.c (SIMPLE_STPNCPY): Remove function.
|
||||||
|
(generic_stpncpy): New function.
|
||||||
|
* benchtests/bench-strcat.c (SIMPLE_STRCAT): Remove function.
|
||||||
|
(generic_strcat): New function.
|
||||||
|
* benchtests/bench-strcpy.c (SIMPLE_STRCPY): Remove function.
|
||||||
|
(generic_strcpy): New function.
|
||||||
|
* benchtests/bench-strncat.c (SIMPLE_STRNCAT): Remove function.
|
||||||
|
(STUPID_STRNCAT): Remove function.
|
||||||
|
(generic_strncat): New function.
|
||||||
|
* benchtests/bench-strncpy.c (SIMPLE_STRNCPY): Remove function.
|
||||||
|
(STUPID_STRNCPY): Remove function.
|
||||||
|
(generic_strncpy): New function.
|
||||||
|
* benchtests/bench-strnlen.c (SIMPLE_STRNLEN): Remove function.
|
||||||
|
(generic_strnlen): New function.
|
||||||
|
(memchr_strnlen): New function.
|
||||||
|
* benchtests/bench-strlen.c (generic_strlen): Define for WIDE.
|
||||||
|
(memchr_strlen): Likewise.
|
||||||
|
|
||||||
2019-04-09 Wilco Dijkstra <wdijkstr@arm.com>
|
2019-04-09 Wilco Dijkstra <wdijkstr@arm.com>
|
||||||
|
|
||||||
* benchtests/bench-strstr.c (input): Add realistic input text.
|
* benchtests/bench-strstr.c (input): Add realistic input text.
|
||||||
|
|
|
@ -22,24 +22,18 @@
|
||||||
# define TEST_NAME "stpcpy"
|
# define TEST_NAME "stpcpy"
|
||||||
#else
|
#else
|
||||||
# define TEST_NAME "wcpcpy"
|
# define TEST_NAME "wcpcpy"
|
||||||
|
# define generic_stpcpy generic_wcpcpy
|
||||||
#endif /* WIDE */
|
#endif /* WIDE */
|
||||||
#include "bench-string.h"
|
#include "bench-string.h"
|
||||||
#ifndef WIDE
|
|
||||||
# define SIMPLE_STPCPY simple_stpcpy
|
|
||||||
#else
|
|
||||||
# define SIMPLE_STPCPY simple_wcpcpy
|
|
||||||
#endif /* WIDE */
|
|
||||||
|
|
||||||
CHAR *SIMPLE_STPCPY (CHAR *, const CHAR *);
|
|
||||||
|
|
||||||
IMPL (SIMPLE_STPCPY, 0)
|
|
||||||
IMPL (STPCPY, 1)
|
|
||||||
|
|
||||||
CHAR *
|
CHAR *
|
||||||
SIMPLE_STPCPY (CHAR *dst, const CHAR *src)
|
generic_stpcpy (CHAR *dst, const CHAR *src)
|
||||||
{
|
{
|
||||||
while ((*dst++ = *src++) != '\0');
|
size_t len = STRLEN (src);
|
||||||
return dst - 1;
|
return (CHAR *) MEMCPY (dst, src, len + 1) + len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IMPL (STPCPY, 1)
|
||||||
|
IMPL (generic_stpcpy, 0)
|
||||||
|
|
||||||
#include "bench-strcpy.c"
|
#include "bench-strcpy.c"
|
||||||
|
|
|
@ -22,49 +22,22 @@
|
||||||
# define TEST_NAME "stpncpy"
|
# define TEST_NAME "stpncpy"
|
||||||
#else
|
#else
|
||||||
# define TEST_NAME "wcpncpy"
|
# define TEST_NAME "wcpncpy"
|
||||||
|
# define generic_stpncpy generic_wcpncpy
|
||||||
#endif /* WIDE */
|
#endif /* WIDE */
|
||||||
#include "bench-string.h"
|
#include "bench-string.h"
|
||||||
#ifndef WIDE
|
|
||||||
# define SIMPLE_STPNCPY simple_stpncpy
|
|
||||||
# define STUPID_STPNCPY stupid_stpncpy
|
|
||||||
#else
|
|
||||||
# define SIMPLE_STPNCPY simple_wcpncpy
|
|
||||||
# define STUPID_STPNCPY stupid_wcpncpy
|
|
||||||
#endif /* WIDE */
|
|
||||||
|
|
||||||
CHAR *SIMPLE_STPNCPY (CHAR *, const CHAR *, size_t);
|
|
||||||
CHAR *STUPID_STPNCPY (CHAR *, const CHAR *, size_t);
|
|
||||||
|
|
||||||
IMPL (STUPID_STPNCPY, 0)
|
|
||||||
IMPL (SIMPLE_STPNCPY, 0)
|
|
||||||
IMPL (STPNCPY, 1)
|
|
||||||
|
|
||||||
CHAR *
|
CHAR *
|
||||||
SIMPLE_STPNCPY (CHAR *dst, const CHAR *src, size_t n)
|
generic_stpncpy (CHAR *dst, const CHAR *src, size_t n)
|
||||||
{
|
|
||||||
while (n--)
|
|
||||||
if ((*dst++ = *src++) == '\0')
|
|
||||||
{
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
for (i = 0; i < n; ++i)
|
|
||||||
dst[i] = '\0';
|
|
||||||
return dst - 1;
|
|
||||||
}
|
|
||||||
return dst;
|
|
||||||
}
|
|
||||||
|
|
||||||
CHAR *
|
|
||||||
STUPID_STPNCPY (CHAR *dst, const CHAR *src, size_t n)
|
|
||||||
{
|
{
|
||||||
size_t nc = STRNLEN (src, n);
|
size_t nc = STRNLEN (src, n);
|
||||||
size_t i;
|
MEMCPY (dst, src, nc);
|
||||||
|
dst += nc;
|
||||||
for (i = 0; i < nc; ++i)
|
if (nc == n)
|
||||||
dst[i] = src[i];
|
return dst;
|
||||||
for (; i < n; ++i)
|
return MEMSET (dst, 0, n - nc);
|
||||||
dst[i] = '\0';
|
|
||||||
return dst + nc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IMPL (STPNCPY, 1)
|
||||||
|
IMPL (generic_stpncpy, 0)
|
||||||
|
|
||||||
#include "bench-strncpy.c"
|
#include "bench-strncpy.c"
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
# define TEST_NAME "strcat"
|
# define TEST_NAME "strcat"
|
||||||
#else
|
#else
|
||||||
# define TEST_NAME "wcscat"
|
# define TEST_NAME "wcscat"
|
||||||
|
# define generic_strcat generic_wcscat
|
||||||
#endif /* WIDE */
|
#endif /* WIDE */
|
||||||
#include "bench-string.h"
|
#include "bench-string.h"
|
||||||
|
|
||||||
|
@ -28,31 +29,25 @@
|
||||||
|
|
||||||
#ifndef WIDE
|
#ifndef WIDE
|
||||||
# define sfmt "s"
|
# define sfmt "s"
|
||||||
# define SIMPLE_STRCAT simple_strcat
|
|
||||||
# define SMALL_CHAR 127
|
# define SMALL_CHAR 127
|
||||||
#else
|
#else
|
||||||
# define sfmt "ls"
|
# define sfmt "ls"
|
||||||
# define SIMPLE_STRCAT simple_wcscat
|
|
||||||
# define SMALL_CHAR 1273
|
# define SMALL_CHAR 1273
|
||||||
#endif /* WIDE */
|
#endif /* WIDE */
|
||||||
|
|
||||||
|
|
||||||
typedef CHAR *(*proto_t) (CHAR *, const CHAR *);
|
typedef CHAR *(*proto_t) (CHAR *, const CHAR *);
|
||||||
CHAR *SIMPLE_STRCAT (CHAR *, const CHAR *);
|
|
||||||
|
|
||||||
IMPL (SIMPLE_STRCAT, 0)
|
|
||||||
IMPL (STRCAT, 1)
|
|
||||||
|
|
||||||
CHAR *
|
CHAR *
|
||||||
SIMPLE_STRCAT (CHAR *dst, const CHAR *src)
|
generic_strcat (CHAR *dst, const CHAR *src)
|
||||||
{
|
{
|
||||||
CHAR *ret = dst;
|
STRCPY (dst + STRLEN (dst), src);
|
||||||
while (*dst++ != '\0');
|
return dst;
|
||||||
--dst;
|
|
||||||
while ((*dst++ = *src++) != '\0');
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IMPL (STRCAT, 1)
|
||||||
|
IMPL (generic_strcat, 0)
|
||||||
|
|
||||||
static void
|
static void
|
||||||
do_one_test (impl_t *impl, CHAR *dst, const CHAR *src)
|
do_one_test (impl_t *impl, CHAR *dst, const CHAR *src)
|
||||||
{
|
{
|
||||||
|
|
|
@ -33,26 +33,19 @@
|
||||||
# define TEST_NAME "strcpy"
|
# define TEST_NAME "strcpy"
|
||||||
# else
|
# else
|
||||||
# define TEST_NAME "wcscpy"
|
# define TEST_NAME "wcscpy"
|
||||||
|
# define generic_strcpy generic_wcscpy
|
||||||
# endif
|
# endif
|
||||||
# include "bench-string.h"
|
#include "bench-string.h"
|
||||||
# ifndef WIDE
|
|
||||||
# define SIMPLE_STRCPY simple_strcpy
|
|
||||||
# else
|
|
||||||
# define SIMPLE_STRCPY simple_wcscpy
|
|
||||||
# endif
|
|
||||||
|
|
||||||
CHAR *SIMPLE_STRCPY (CHAR *, const CHAR *);
|
|
||||||
|
|
||||||
IMPL (SIMPLE_STRCPY, 0)
|
|
||||||
IMPL (STRCPY, 1)
|
|
||||||
|
|
||||||
CHAR *
|
CHAR *
|
||||||
SIMPLE_STRCPY (CHAR *dst, const CHAR *src)
|
generic_strcpy (CHAR *dst, const CHAR *src)
|
||||||
{
|
{
|
||||||
CHAR *ret = dst;
|
return MEMCPY (dst, src, STRLEN (src) + 1);
|
||||||
while ((*dst++ = *src++) != '\0');
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IMPL (STRCPY, 1)
|
||||||
|
IMPL (generic_strcpy, 0)
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef CHAR *(*proto_t) (CHAR *, const CHAR *);
|
typedef CHAR *(*proto_t) (CHAR *, const CHAR *);
|
||||||
|
|
|
@ -21,6 +21,8 @@
|
||||||
# define TEST_NAME "strlen"
|
# define TEST_NAME "strlen"
|
||||||
#else
|
#else
|
||||||
# define TEST_NAME "wcslen"
|
# define TEST_NAME "wcslen"
|
||||||
|
# define generic_strlen generic_wcslen
|
||||||
|
# define memchr_strlen wcschr_wcslen
|
||||||
#endif
|
#endif
|
||||||
#include "bench-string.h"
|
#include "bench-string.h"
|
||||||
|
|
||||||
|
|
|
@ -21,41 +21,33 @@
|
||||||
# define TEST_NAME "strncat"
|
# define TEST_NAME "strncat"
|
||||||
#else
|
#else
|
||||||
# define TEST_NAME "wcsncat"
|
# define TEST_NAME "wcsncat"
|
||||||
|
# define generic_strncat generic_wcsncat
|
||||||
#endif /* WIDE */
|
#endif /* WIDE */
|
||||||
#include "bench-string.h"
|
#include "bench-string.h"
|
||||||
|
|
||||||
#define BIG_CHAR MAX_CHAR
|
#define BIG_CHAR MAX_CHAR
|
||||||
|
|
||||||
#ifndef WIDE
|
#ifndef WIDE
|
||||||
# define SIMPLE_STRNCAT simple_strncat
|
|
||||||
# define STUPID_STRNCAT stupid_strncat
|
|
||||||
# define SMALL_CHAR 127
|
# define SMALL_CHAR 127
|
||||||
#else
|
#else
|
||||||
# define SIMPLE_STRNCAT simple_wcsncat
|
|
||||||
# define STUPID_STRNCAT stupid_wcsncat
|
|
||||||
# define SMALL_CHAR 1273
|
# define SMALL_CHAR 1273
|
||||||
#endif /* WIDE */
|
#endif /* WIDE */
|
||||||
|
|
||||||
typedef CHAR *(*proto_t) (CHAR *, const CHAR *, size_t);
|
typedef CHAR *(*proto_t) (CHAR *, const CHAR *, size_t);
|
||||||
CHAR *STUPID_STRNCAT (CHAR *, const CHAR *, size_t);
|
|
||||||
CHAR *SIMPLE_STRNCAT (CHAR *, const CHAR *, size_t);
|
|
||||||
|
|
||||||
IMPL (STUPID_STRNCAT, 0)
|
|
||||||
IMPL (STRNCAT, 2)
|
|
||||||
|
|
||||||
CHAR *
|
CHAR *
|
||||||
STUPID_STRNCAT (CHAR *dst, const CHAR *src, size_t n)
|
generic_strncat (CHAR *dst, const CHAR *src, size_t n)
|
||||||
{
|
{
|
||||||
CHAR *ret = dst;
|
CHAR *end = dst + STRLEN (dst);
|
||||||
while (*dst++ != '\0');
|
n = STRNLEN (src, n);
|
||||||
--dst;
|
end[n] = 0;
|
||||||
while (n--)
|
MEMCPY (end, src, n);
|
||||||
if ((*dst++ = *src++) == '\0')
|
return dst;
|
||||||
return ret;
|
|
||||||
*dst = '\0';
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IMPL (STRNCAT, 2)
|
||||||
|
IMPL (generic_strncat, 0)
|
||||||
|
|
||||||
static void
|
static void
|
||||||
do_one_test (impl_t *impl, CHAR *dst, const CHAR *src, size_t n)
|
do_one_test (impl_t *impl, CHAR *dst, const CHAR *src, size_t n)
|
||||||
{
|
{
|
||||||
|
|
|
@ -31,49 +31,22 @@
|
||||||
# define TEST_NAME "strncpy"
|
# define TEST_NAME "strncpy"
|
||||||
# else
|
# else
|
||||||
# define TEST_NAME "wcsncpy"
|
# define TEST_NAME "wcsncpy"
|
||||||
|
# define generic_strncpy generic_wcsncpy
|
||||||
# endif /* WIDE */
|
# endif /* WIDE */
|
||||||
# include "bench-string.h"
|
# include "bench-string.h"
|
||||||
# ifndef WIDE
|
|
||||||
# define SIMPLE_STRNCPY simple_strncpy
|
|
||||||
# define STUPID_STRNCPY stupid_strncpy
|
|
||||||
# else
|
|
||||||
# define SIMPLE_STRNCPY simple_wcsncpy
|
|
||||||
# define STUPID_STRNCPY stupid_wcsncpy
|
|
||||||
# endif /* WIDE */
|
|
||||||
|
|
||||||
CHAR *SIMPLE_STRNCPY (CHAR *, const CHAR *, size_t);
|
|
||||||
CHAR *STUPID_STRNCPY (CHAR *, const CHAR *, size_t);
|
|
||||||
|
|
||||||
IMPL (STUPID_STRNCPY, 0)
|
|
||||||
IMPL (SIMPLE_STRNCPY, 0)
|
|
||||||
IMPL (STRNCPY, 1)
|
|
||||||
|
|
||||||
CHAR *
|
CHAR *
|
||||||
SIMPLE_STRNCPY (CHAR *dst, const CHAR *src, size_t n)
|
generic_strncpy (CHAR *dst, const CHAR *src, size_t n)
|
||||||
{
|
|
||||||
CHAR *ret = dst;
|
|
||||||
while (n--)
|
|
||||||
if ((*dst++ = *src++) == '\0')
|
|
||||||
{
|
|
||||||
while (n--)
|
|
||||||
*dst++ = '\0';
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
CHAR *
|
|
||||||
STUPID_STRNCPY (CHAR *dst, const CHAR *src, size_t n)
|
|
||||||
{
|
{
|
||||||
size_t nc = STRNLEN (src, n);
|
size_t nc = STRNLEN (src, n);
|
||||||
size_t i;
|
if (nc != n)
|
||||||
|
MEMSET (dst + nc, 0, n - nc);
|
||||||
for (i = 0; i < nc; ++i)
|
return MEMCPY (dst, src, nc);
|
||||||
dst[i] = src[i];
|
|
||||||
for (; i < n; ++i)
|
|
||||||
dst[i] = '\0';
|
|
||||||
return dst;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IMPL (STRNCPY, 1)
|
||||||
|
IMPL (generic_strncpy, 0)
|
||||||
|
|
||||||
#endif /* !STRNCPY_RESULT */
|
#endif /* !STRNCPY_RESULT */
|
||||||
|
|
||||||
typedef CHAR *(*proto_t) (CHAR *, const CHAR *, size_t);
|
typedef CHAR *(*proto_t) (CHAR *, const CHAR *, size_t);
|
||||||
|
|
|
@ -21,6 +21,8 @@
|
||||||
# define TEST_NAME "strnlen"
|
# define TEST_NAME "strnlen"
|
||||||
#else
|
#else
|
||||||
# define TEST_NAME "wcsnlen"
|
# define TEST_NAME "wcsnlen"
|
||||||
|
# define generic_strnlen generic_wcsnlen
|
||||||
|
# define memchr_strnlen wcschr_wcsnlen
|
||||||
#endif /* WIDE */
|
#endif /* WIDE */
|
||||||
#include "bench-string.h"
|
#include "bench-string.h"
|
||||||
|
|
||||||
|
@ -28,27 +30,24 @@
|
||||||
|
|
||||||
#ifndef WIDE
|
#ifndef WIDE
|
||||||
# define MIDDLE_CHAR 127
|
# define MIDDLE_CHAR 127
|
||||||
# define SIMPLE_STRNLEN simple_strnlen
|
|
||||||
#else
|
#else
|
||||||
# define MIDDLE_CHAR 1121
|
# define MIDDLE_CHAR 1121
|
||||||
# define SIMPLE_STRNLEN simple_wcsnlen
|
|
||||||
#endif /* WIDE */
|
#endif /* WIDE */
|
||||||
|
|
||||||
typedef size_t (*proto_t) (const CHAR *, size_t);
|
typedef size_t (*proto_t) (const CHAR *, size_t);
|
||||||
size_t SIMPLE_STRNLEN (const CHAR *, size_t);
|
size_t generic_strnlen (const CHAR *, size_t);
|
||||||
|
|
||||||
IMPL (SIMPLE_STRNLEN, 0)
|
|
||||||
IMPL (STRNLEN, 1)
|
|
||||||
|
|
||||||
size_t
|
size_t
|
||||||
SIMPLE_STRNLEN (const CHAR *s, size_t maxlen)
|
memchr_strnlen (const CHAR *s, size_t maxlen)
|
||||||
{
|
{
|
||||||
size_t i;
|
const CHAR *s1 = MEMCHR (s, 0, maxlen);
|
||||||
|
return (s1 == NULL) ? maxlen : s1 - s;
|
||||||
for (i = 0; i < maxlen && s[i]; ++i);
|
|
||||||
return i;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IMPL (STRNLEN, 1)
|
||||||
|
IMPL (memchr_strnlen, 0)
|
||||||
|
IMPL (generic_strnlen, 0)
|
||||||
|
|
||||||
static void
|
static void
|
||||||
do_one_test (impl_t *impl, const CHAR *s, size_t maxlen, size_t exp_len)
|
do_one_test (impl_t *impl, const CHAR *s, size_t maxlen, size_t exp_len)
|
||||||
{
|
{
|
||||||
|
@ -146,3 +145,13 @@ test_main (void)
|
||||||
}
|
}
|
||||||
|
|
||||||
#include <support/test-driver.c>
|
#include <support/test-driver.c>
|
||||||
|
|
||||||
|
#define libc_hidden_def(X)
|
||||||
|
#ifndef WIDE
|
||||||
|
# undef STRNLEN
|
||||||
|
# define STRNLEN generic_strnlen
|
||||||
|
# include <string/strnlen.c>
|
||||||
|
#else
|
||||||
|
# define WCSNLEN generic_strnlen
|
||||||
|
# include <wcsmbs/wcsnlen.c>
|
||||||
|
#endif
|
||||||
|
|
|
@ -17,4 +17,5 @@
|
||||||
<http://www.gnu.org/licenses/>. */
|
<http://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
#define WIDE 1
|
#define WIDE 1
|
||||||
|
#define __wmemchr wmemchr
|
||||||
#include "bench-strnlen.c"
|
#include "bench-strnlen.c"
|
||||||
|
|
Loading…
Reference in New Issue