about summary refs log tree commit diff
path: root/benchtests/bench-strnlen.c
diff options
context:
space:
mode:
Diffstat (limited to 'benchtests/bench-strnlen.c')
-rw-r--r--benchtests/bench-strnlen.c71
1 files changed, 46 insertions, 25 deletions
diff --git a/benchtests/bench-strnlen.c b/benchtests/bench-strnlen.c
index 35266e5bf9..cbdce75b74 100644
--- a/benchtests/bench-strnlen.c
+++ b/benchtests/bench-strnlen.c
@@ -17,17 +17,36 @@
    <http://www.gnu.org/licenses/>.  */
 
 #define TEST_MAIN
-#define TEST_NAME "strnlen"
+#ifndef WIDE
+# define TEST_NAME "strnlen"
+#else
+# define TEST_NAME "wcsnlen"
+#endif /* WIDE */
 #include "bench-string.h"
 
-typedef size_t (*proto_t) (const char *, size_t);
-size_t simple_strnlen (const char *, size_t);
-
-IMPL (simple_strnlen, 0)
-IMPL (strnlen, 1)
+#ifndef WIDE
+# define STRNLEN strnlen
+# define CHAR char
+# define BIG_CHAR CHAR_MAX
+# define MIDDLE_CHAR 127
+# define SIMPLE_STRNLEN simple_strnlen
+#else
+# include <wchar.h>
+# define STRNLEN wcsnlen
+# define CHAR wchar_t
+# define BIG_CHAR WCHAR_MAX
+# define MIDDLE_CHAR 1121
+# define SIMPLE_STRNLEN simple_wcsnlen
+#endif /* WIDE */
+
+typedef size_t (*proto_t) (const CHAR *, size_t);
+size_t SIMPLE_STRNLEN (const CHAR *, size_t);
+
+IMPL (SIMPLE_STRNLEN, 0)
+IMPL (STRNLEN, 1)
 
 size_t
-simple_strnlen (const char *s, size_t maxlen)
+SIMPLE_STRNLEN (const CHAR *s, size_t maxlen)
 {
   size_t i;
 
@@ -36,7 +55,7 @@ simple_strnlen (const char *s, size_t maxlen)
 }
 
 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)
 {
   size_t len = CALL (impl, s, maxlen), i, iters = INNER_LOOP_ITERS;
   timing_t start, stop, cur;
@@ -66,18 +85,20 @@ do_test (size_t align, size_t len, size_t maxlen, int max_char)
 {
   size_t i;
 
-  align &= 7;
-  if (align + len >= page_size)
+  align &= 63;
+  if ((align + len) * sizeof (CHAR) >= page_size)
     return;
 
+  CHAR *buf = (CHAR *) (buf1);
+
   for (i = 0; i < len; ++i)
-    buf1[align + i] = 1 + 7 * i % max_char;
-  buf1[align + len] = 0;
+    buf[align + i] = 1 + 7 * i % max_char;
+  buf[align + len] = 0;
 
   printf ("Length %4zd, alignment %2zd:", len, align);
 
   FOR_EACH_IMPL (impl, 0)
-    do_one_test (impl, (char *) (buf1 + align), maxlen, MIN (len, maxlen));
+    do_one_test (impl, (CHAR *) (buf + align), maxlen, MIN (len, maxlen));
 
   putchar ('\n');
 }
@@ -96,34 +117,34 @@ test_main (void)
 
   for (i = 1; i < 8; ++i)
     {
-      do_test (0, i, i - 1, 127);
-      do_test (0, i, i, 127);
-      do_test (0, i, i + 1, 127);
+      do_test (0, i, i - 1, MIDDLE_CHAR);
+      do_test (0, i, i, MIDDLE_CHAR);
+      do_test (0, i, i + 1, MIDDLE_CHAR);
     }
 
   for (i = 1; i < 8; ++i)
     {
-      do_test (i, i, i - 1, 127);
-      do_test (i, i, i, 127);
-      do_test (i, i, i + 1, 127);
+      do_test (i, i, i - 1, MIDDLE_CHAR);
+      do_test (i, i, i, MIDDLE_CHAR);
+      do_test (i, i, i + 1, MIDDLE_CHAR);
     }
 
   for (i = 2; i <= 10; ++i)
     {
-      do_test (0, 1 << i, 5000, 127);
-      do_test (1, 1 << i, 5000, 127);
+      do_test (0, 1 << i, 5000, MIDDLE_CHAR);
+      do_test (1, 1 << i, 5000, MIDDLE_CHAR);
     }
 
   for (i = 1; i < 8; ++i)
-    do_test (0, i, 5000, 255);
+    do_test (0, i, 5000, BIG_CHAR);
 
   for (i = 1; i < 8; ++i)
-    do_test (i, i, 5000, 255);
+    do_test (i, i, 5000, BIG_CHAR);
 
   for (i = 2; i <= 10; ++i)
     {
-      do_test (0, 1 << i, 5000, 255);
-      do_test (1, 1 << i, 5000, 255);
+      do_test (0, 1 << i, 5000, BIG_CHAR);
+      do_test (1, 1 << i, 5000, BIG_CHAR);
     }
 
   return ret;