From 3ae725dfb6d7f61447d27d00ed83e573bd5454f4 Mon Sep 17 00:00:00 2001 From: Wilco Dijkstra Date: Mon, 16 Jul 2018 17:50:09 +0100 Subject: Improve strstr performance Improve strstr performance. Strstr tends to be slow because it uses many calls to memchr and a slow byte loop to scan for the next match. Performance is significantly improved by using strnlen on larger blocks and using strchr to search for the next matching character. strcasestr can also use strnlen to scan ahead, and memmem can use memchr to check for the next match. On the GLIBC bench tests the performance gains on Cortex-A72 are: strstr: +25% strcasestr: +4.3% memmem: +18% On a 256KB dataset strstr performance improves by 67%, strcasestr by 47%. Reviewd-by: Adhemerval Zanella --- benchtests/bench-strcasestr.c | 1 + benchtests/bench-strstr.c | 1 + 2 files changed, 2 insertions(+) (limited to 'benchtests') diff --git a/benchtests/bench-strcasestr.c b/benchtests/bench-strcasestr.c index e6659ea79e..4337e0c18d 100644 --- a/benchtests/bench-strcasestr.c +++ b/benchtests/bench-strcasestr.c @@ -24,6 +24,7 @@ #define STRCASESTR simple_strcasestr #define NO_ALIAS #define __strncasecmp strncasecmp +#define __strnlen strnlen #include "../string/strcasestr.c" diff --git a/benchtests/bench-strstr.c b/benchtests/bench-strstr.c index c30cd10785..a31294e3c9 100644 --- a/benchtests/bench-strstr.c +++ b/benchtests/bench-strstr.c @@ -23,6 +23,7 @@ #define STRSTR simple_strstr #define libc_hidden_builtin_def(X) +#define __strnlen strnlen #include "../string/strstr.c" -- cgit 1.4.1