diff --git a/benchtests/bench-strstr.c b/benchtests/bench-strstr.c
index a31294e3c96d80a4fd61bb5b423a825fe54d3227..8805e9205a05e3decf4b9fc7dcbb05bcfe78f39a 100644
--- a/benchtests/bench-strstr.c
+++ b/benchtests/bench-strstr.c
@@ -16,63 +16,143 @@
Â Â Â  License along with the GNU C Library; if not, see
Â Â Â  <http://www.gnu.org/licenses/>.Â  */
Â 
+#define MIN_PAGE_SIZE 131072
Â #define TEST_MAIN
Â #define TEST_NAME "strstr"
Â #include "bench-string.h"
Â 
Â 
-#define STRSTR simple_strstr
+#define STRSTR generic_strstr
Â #define libc_hidden_builtin_def(X)
Â #define __strnlen strnlen
Â #include "../string/strstr.c"
Â 
+static const char input[] =
+"This manual is written with the assumption that you are at least "
+"somewhat familiar with the C programming language and basic programming "
+"concepts.Â  Specifically, familiarity with ISO standard C (*note ISO "
+"C::), rather than â€œtraditionalâ€ pre-ISO C dialects, is assumed.\n"
+
+"Â Â  The GNU C Library includes several â€œheader filesâ€, each of which "
+"provides definitions and declarations for a group of related facilities; "
+"this information is used by the C compiler when processing your program. "
+"For example, the header file â€˜stdio.hâ€™ declares facilities for "
+"performing input and output, and the header file â€˜string.hâ€™ declares "
+"string processing utilities.Â  The organization of this manual generally "
+"follows the same division as the header files.\n"
+
+"Â Â  If you are reading this manual for the first time, you should read "
+"all of the introductory material and skim the remaining chapters.Â  There "
+"are a _lot_ of functions in the GNU C Library and itâ€™s not realistic to "
+"expect that you will be able to remember exactly _how_ to use each and "
+"every one of them.Â  Itâ€™s more important to become generally familiar "
+"with the kinds of facilities that the library provides, so that when you "
+"are writing your programs you can recognize _when_ to make use of "
+"library functions, and _where_ in this manual you can find more specific "
+"information about them.\n";
+
Â 
Â static char *
-stupid_strstr (const char *s1, const char *s2)
+basic_strstr (const char *s1, const char *s2)
Â {
-Â  ssize_t s1len = strlen (s1);
-Â  ssize_t s2len = strlen (s2);
+Â  size_t i;
+Â  int c = s2[0];
Â 
-Â  if (s2len > s1len)
-Â Â Â  return NULL;
+Â  if (c == 0)
+Â Â Â  return (char*)s1;
Â 
-Â  for (ssize_t i = 0; i <= s1len - s2len; ++i)
+Â  for ( ; s1[0] != '\0'; s1++)
Â Â Â Â  {
-Â Â Â Â Â  size_t j;
-Â Â Â Â Â  for (j = 0; j < s2len; ++j)
-Â Â Â Â Â Â  if (s1[i + j] != s2[j])
+Â Â Â Â Â  if (s1[0] != c)
+Â Â Â Â Â Â  continue;
+Â Â Â Â Â  for (i = 1; s2[i] != 0; i++)
+Â Â Â Â Â Â  if (s1[i] != s2[i])
Â Â Â Â Â Â Â Â Â Â  break;
-Â Â Â Â Â  if (j == s2len)
-Â Â Â Â Â Â  return (char *) s1 + i;
+Â Â Â Â Â  if (s2[i] == '\0')
+Â Â Â Â Â Â  return (char*)s1;
Â Â Â Â  }
Â 
Â Â  return NULL;
Â }
Â 
+#define RETURN_TYPE char *
+#define AVAILABLE(h, h_l, j, n_l)Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  \
+Â  (((j) + (n_l) <= (h_l)) \
+Â Â  || ((h_l) += __strnlen ((void*)((h) + (h_l)), (n_l) + 512), \
+Â Â Â Â Â Â  (j) + (n_l) <= (h_l)))
+#define CHECK_EOL (1)
+#define RET0_IF_0(a) if (!a) goto ret0
+#define FASTSEARCH(S,C,N) (void*) strchr ((void*)(S), (C))
+#define LONG_NEEDLE_THRESHOLD 32U
+
+static char *
+twoway_strstr (const char *haystack, const char *needle)
+{
+Â  size_t needle_len; /* Length of NEEDLE.Â  */
+Â  size_t haystack_len; /* Known minimum length of HAYSTACK.Â  */
+
+Â  /* Handle empty NEEDLE special case.Â  */
+Â  if (needle[0] == '\0')
+Â Â Â  return (char *) haystack;
+
+Â  /* Skip until we find the first matching char from NEEDLE.Â  */
+Â  haystack = strchr (haystack, needle[0]);
+Â  if (haystack == NULL || needle[1] == '\0')
+Â Â Â  return (char *) haystack;
+
+Â  /* Ensure HAYSTACK length is at least as long as NEEDLE length.
+Â Â Â Â  Since a match may occur early on in a huge HAYSTACK, use strnlen
+Â Â Â Â  and read ahead a few cachelines for improved performance.Â  */
+Â  needle_len = strlen (needle);
+Â  haystack_len = __strnlen (haystack, needle_len + 256);
+Â  if (haystack_len < needle_len)
+Â Â Â  return NULL;
+
+Â  /* Check whether we have a match.Â  This improves performance since we avoid
+Â Â Â Â  the initialization overhead of the two-way algorithm.Â  */
+Â  if (memcmp (haystack, needle, needle_len) == 0)
+Â Â Â  return (char *) haystack;
+
+Â  /* Perform the search.Â  Abstract memory is considered to be an array
+Â Â Â Â  of 'unsigned char' values, not an array of 'char' values.Â  See
+Â Â Â Â  ISO C 99 section 6.2.6.1.Â  */
+Â  if (needle_len < LONG_NEEDLE_THRESHOLD)
+Â Â Â  return two_way_short_needle ((const unsigned char *) haystack,
+Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  haystack_len,
+Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  (const unsigned char *) needle, needle_len);
+Â  return two_way_long_needle ((const unsigned char *) haystack, haystack_len,
+Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  (const unsigned char *) needle, needle_len);
+}
Â 
Â typedef char *(*proto_t) (const char *, const char *);
Â 
-IMPL (stupid_strstr, 0)
-IMPL (simple_strstr, 0)
Â IMPL (strstr, 1)
-
+IMPL (generic_strstr, 0)
+IMPL (twoway_strstr, 0)
+IMPL (basic_strstr, 0)
Â 
Â static void
Â do_one_test (impl_t *impl, const char *s1, const char *s2, char *exp_result)
Â {
Â Â  size_t i, iters = INNER_LOOP_ITERS;
Â Â  timing_t start, stop, cur;
+Â  char *res;
Â 
Â Â  TIMING_NOW (start);
Â Â  for (i = 0; i < iters; ++i)
-Â Â Â  {
-Â Â Â Â Â  CALL (impl, s1, s2);
-Â Â Â  }
+Â Â Â  res = CALL (impl, s1, s2);
Â Â  TIMING_NOW (stop);
Â 
Â Â  TIMING_DIFF (cur, start, stop);
Â 
Â Â  TIMING_PRINT_MEAN ((double) cur, (double) iters);
+
+Â  if (res != exp_result)
+Â Â Â  {
+Â Â Â Â Â  error (0, 0, "Wrong result in function %s %s %s", impl->name,
+Â Â Â Â Â Â Â Â Â Â Â  res, exp_result);
+Â Â Â Â Â  ret = 1;
+Â Â Â  }
Â }
Â 
Â 
@@ -83,36 +163,42 @@ do_test (size_t align1, size_t align2, size_t len1, size_t len2,
Â Â  char *s1 = (char *) (buf1 + align1);
Â Â  char *s2 = (char *) (buf2 + align2);
Â 
-Â  static const char d[] = "1234567890abcdef";
-#define dl (sizeof (d) - 1)
-Â  char *ss2 = s2;
-Â  for (size_t l = len2; l > 0; l = l > dl ? l - dl : 0)
-Â Â Â  {
-Â Â Â Â Â  size_t t = l > dl ? dl : l;
-Â Â Â Â Â  ss2 = mempcpy (ss2, d, t);
-Â Â Â  }
-Â  s2[len2] = '\0';
+Â  size_t size = sizeof (input) - 1;
+Â  size_t pos = (len1 + len2) % size;
Â 
-Â  if (fail)
+Â  char *ss2 = s2;
+Â  for (size_t l = len2; l > 0; l = l > size ? l - size : 0)
Â Â Â Â  {
-Â Â Â Â Â  char *ss1 = s1;
-Â Â Â Â Â  for (size_t l = len1; l > 0; l = l > dl ? l - dl : 0)
+Â Â Â Â Â  size_t t = l > size ? size : l;
+Â Â Â Â Â  if (pos + t <= size)
+Â Â Â Â Â Â  ss2 = mempcpy (ss2, input + pos, t);
+Â Â Â Â Â  else
Â Â Â Â Â Â Â Â  {
-Â Â Â Â Â Â Â Â  size_t t = l > dl ? dl : l;
-Â Â Â Â Â Â Â Â  memcpy (ss1, d, t);
-Â Â Â Â Â Â Â Â  ++ss1[len2 > 7 ? 7 : len2 - 1];
-Â Â Â Â Â Â Â Â  ss1 += t;
+Â Â Â Â Â Â Â Â  ss2 = mempcpy (ss2, input + pos, size - pos);
+Â Â Â Â Â Â Â Â  ss2 = mempcpy (ss2, input, t - (size - pos));
Â Â Â Â Â Â Â Â  }
Â Â Â Â  }
-Â  else
+Â  s2[len2] = '\0';
+
+Â  char *ss1 = s1;
+Â  for (size_t l = len1; l > 0; l = l > size ? l - size : 0)
Â Â Â Â  {
-Â Â Â Â Â  memset (s1, '0', len1);
-Â Â Â Â Â  memcpy (s1 + len1 - len2, s2, len2);
+Â Â Â Â Â  size_t t = l > size ? size : l;
+Â Â Â Â Â  memcpy (ss1, input, t);
+Â Â Â Â Â  ss1 += t;
Â Â Â Â  }
+
+Â  if (!fail)
+Â Â Â  memcpy (s1 + len1 - len2, s2, len2);
Â Â  s1[len1] = '\0';
Â 
-Â  printf ("Length %4zd/%zd, alignment %2zd/%2zd, %s:",
-Â Â Â Â Â Â Â Â  len1, len2, align1, align2, fail ? "fail" : "found");
+Â  /* Remove any accidental matches except for the last if !fail.Â  */
+Â  for (ss1 = basic_strstr (s1, s2); ss1; ss1 = basic_strstr (ss1 + 1, s2))
+Â Â Â  if (fail || ss1 != s1 + len1 - len2)
+Â Â Â Â Â  ++ss1[len2 / 2];
+
+Â  printf ("Length %4zd/%3zd, alignment %2zd/%2zd, %s:",
+Â Â Â Â Â Â Â Â  len1, len2, align1, align2, fail ? "fail " : "found");
Â 
Â Â  FOR_EACH_IMPL (impl, 0)
Â Â Â Â  do_one_test (impl, s1, s2, fail ? NULL : s1 + len1 - len2);
@@ -130,48 +216,19 @@ test_main (void)
Â Â Â Â  printf ("\t%s", impl->name);
Â Â  putchar ('\n');
Â 
-Â  for (size_t klen = 2; klen < 32; ++klen)
-Â Â Â  for (size_t hlen = 2 * klen; hlen < 16 * klen; hlen += klen)
+Â  for (size_t hlen = 64; hlen <= 256; hlen += 32)
+Â Â Â  for (size_t klen = 1; klen <= 16; klen++)
Â Â Â Â Â Â  {
-Â Â Â Â Â Â  do_test (0, 0, hlen, klen, 0);
-Â Â Â Â Â Â  do_test (0, 0, hlen, klen, 1);
-Â Â Â Â Â Â  do_test (0, 3, hlen, klen, 0);
-Â Â Â Â Â Â  do_test (0, 3, hlen, klen, 1);
-Â Â Â Â Â Â  do_test (0, 9, hlen, klen, 0);
+Â Â Â Â Â Â  do_test (1, 3, hlen, klen, 0);
Â Â Â Â Â Â Â Â  do_test (0, 9, hlen, klen, 1);
-Â Â Â Â Â Â  do_test (0, 15, hlen, klen, 0);
-Â Â Â Â Â Â  do_test (0, 15, hlen, klen, 1);
-
-Â Â Â Â Â Â  do_test (3, 0, hlen, klen, 0);
-Â Â Â Â Â Â  do_test (3, 0, hlen, klen, 1);
-Â Â Â Â Â Â  do_test (3, 3, hlen, klen, 0);
-Â Â Â Â Â Â  do_test (3, 3, hlen, klen, 1);
-Â Â Â Â Â Â  do_test (3, 9, hlen, klen, 0);
-Â Â Â Â Â Â  do_test (3, 9, hlen, klen, 1);
-Â Â Â Â Â Â  do_test (3, 15, hlen, klen, 0);
-Â Â Â Â Â Â  do_test (3, 15, hlen, klen, 1);
-
-Â Â Â Â Â Â  do_test (9, 0, hlen, klen, 0);
-Â Â Â Â Â Â  do_test (9, 0, hlen, klen, 1);
-Â Â Â Â Â Â  do_test (9, 3, hlen, klen, 0);
-Â Â Â Â Â Â  do_test (9, 3, hlen, klen, 1);
-Â Â Â Â Â Â  do_test (9, 9, hlen, klen, 0);
-Â Â Â Â Â Â  do_test (9, 9, hlen, klen, 1);
-Â Â Â Â Â Â  do_test (9, 15, hlen, klen, 0);
-Â Â Â Â Â Â  do_test (9, 15, hlen, klen, 1);
-
-Â Â Â Â Â Â  do_test (15, 0, hlen, klen, 0);
-Â Â Â Â Â Â  do_test (15, 0, hlen, klen, 1);
-Â Â Â Â Â Â  do_test (15, 3, hlen, klen, 0);
-Â Â Â Â Â Â  do_test (15, 3, hlen, klen, 1);
-Â Â Â Â Â Â  do_test (15, 9, hlen, klen, 0);
-Â Â Â Â Â Â  do_test (15, 9, hlen, klen, 1);
-Â Â Â Â Â Â  do_test (15, 15, hlen, klen, 0);
-Â Â Â Â Â Â  do_test (15, 15, hlen, klen, 1);
Â Â Â Â Â Â  }
Â 
-Â  do_test (0, 0, page_size - 1, 16, 0);
-Â  do_test (0, 0, page_size - 1, 16, 1);
+Â  for (size_t hlen = 256; hlen <= 65536; hlen *= 2)
+Â Â Â  for (size_t klen = 16; klen <= 256; klen *= 2)
+Â Â Â Â Â  {
+Â Â Â Â Â Â  do_test (1, 11, hlen, klen, 0);
+Â Â Â Â Â Â  do_test (14, 5, hlen, klen, 1);
+Â Â Â Â Â  }
Â 
Â Â  return ret;
Â }    
