about summary refs log tree commit diff
path: root/benchtests/bench-memchr.c
diff options
context:
space:
mode:
authorNoah Goldstein <goldstein.w.n@gmail.com>2022-05-27 18:25:40 -0500
committerNoah Goldstein <goldstein.w.n@gmail.com>2022-05-27 22:52:37 -0500
commita8f62164b1d0ea6583c9c5d05aa4be9c946c2004 (patch)
tree9110dd175b6a6aa200a9711684f4915d4eea23c0 /benchtests/bench-memchr.c
parentefa7936e4c91b1c260d03614bb26858fbb8a0204 (diff)
downloadglibc-a8f62164b1d0ea6583c9c5d05aa4be9c946c2004.tar.gz
glibc-a8f62164b1d0ea6583c9c5d05aa4be9c946c2004.tar.xz
glibc-a8f62164b1d0ea6583c9c5d05aa4be9c946c2004.zip
benchtests: Improve benchtests for strstr, memmem, and memchr
1. Use json_ctx for output to help standardize format across all
   benchtests.

2. Add some additional tests to strstr and memchr expanding alignments
   and adding more small values.
Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
Diffstat (limited to 'benchtests/bench-memchr.c')
-rw-r--r--benchtests/bench-memchr.c108
1 files changed, 72 insertions, 36 deletions
diff --git a/benchtests/bench-memchr.c b/benchtests/bench-memchr.c
index fb0284f523..4d7212332f 100644
--- a/benchtests/bench-memchr.c
+++ b/benchtests/bench-memchr.c
@@ -53,8 +53,11 @@ SIMPLE_MEMCHR (const CHAR *s, int c, size_t n)
 }
 #endif /* !USE_AS_MEMRCHR */
 
+#include "json-lib.h"
+
 static void
-do_one_test (impl_t *impl, const CHAR *s, int c, size_t n)
+do_one_test (json_ctx_t *json_ctx, impl_t *impl, const CHAR *s, int c,
+	     size_t n)
 {
   size_t i, iters = INNER_LOOP_ITERS_LARGE;
   timing_t start, stop, cur;
@@ -68,15 +71,16 @@ do_one_test (impl_t *impl, const CHAR *s, int c, size_t n)
 
   TIMING_DIFF (cur, start, stop);
 
-  TIMING_PRINT_MEAN ((double) cur, (double) iters);
+  json_element_double (json_ctx, (double) cur / (double) iters);
 }
 
 static void
-do_test (size_t align, size_t pos, size_t len, int seek_char)
+do_test (json_ctx_t *json_ctx, size_t align, size_t pos, size_t len,
+	 int seek_char)
 {
   size_t i;
 
-  align &= 7;
+  align &= getpagesize () - 1;
   if ((align + len) * sizeof (CHAR) >= page_size)
     return;
 
@@ -100,67 +104,99 @@ do_test (size_t align, size_t pos, size_t len, int seek_char)
       buf[align + len] = seek_char;
     }
 
-  printf ("Length %4zd, position %4zd, alignment %2zd:",
-	  len, pos, align);
+  json_element_object_begin (json_ctx);
+  json_attr_uint (json_ctx, "align", align);
+  json_attr_uint (json_ctx, "pos", pos);
+  json_attr_uint (json_ctx, "len", len);
+  json_attr_uint (json_ctx, "seek_char", seek_char);
+
+  json_array_begin (json_ctx, "timings");
 
   FOR_EACH_IMPL (impl, 0)
-    do_one_test (impl, (CHAR *) (buf + align), seek_char, len);
+    do_one_test (json_ctx, impl, (CHAR *) (buf + align), seek_char, len);
 
-  putchar ('\n');
+  json_array_end (json_ctx);
+  json_element_object_end (json_ctx);
 }
 
 int
 test_main (void)
 {
   size_t i;
-
+  json_ctx_t json_ctx;
   test_init ();
 
-  printf ("%20s", "");
+  json_init (&json_ctx, 0, stdout);
+
+  json_document_begin (&json_ctx);
+  json_attr_string (&json_ctx, "timing_type", TIMING_TYPE);
+
+  json_attr_object_begin (&json_ctx, "functions");
+  json_attr_object_begin (&json_ctx, TEST_NAME);
+  json_attr_string (&json_ctx, "bench-variant", "");
+
+  json_array_begin (&json_ctx, "ifuncs");
   FOR_EACH_IMPL (impl, 0)
-    printf ("\t%s", impl->name);
-  putchar ('\n');
+    json_element_string (&json_ctx, impl->name);
+  json_array_end (&json_ctx);
+
+  json_array_begin (&json_ctx, "results");
 
   for (i = 1; i < 8; ++i)
     {
-      do_test (0, 16 << i, 2048, 23);
-      do_test (i, 64, 256, 23);
-      do_test (0, 16 << i, 2048, 0);
-      do_test (i, 64, 256, 0);
+      do_test (&json_ctx, 0, 16 << i, 2048, 23);
+      do_test (&json_ctx, i, 64, 256, 23);
+      do_test (&json_ctx, 0, 16 << i, 2048, 0);
+      do_test (&json_ctx, i, 64, 256, 0);
+
+      do_test (&json_ctx, getpagesize () - 15, 64, 256, 0);
 #ifdef USE_AS_MEMRCHR
       /* Also test the position close to the beginning for memrchr.  */
-      do_test (0, i, 256, 23);
-      do_test (0, i, 256, 0);
-      do_test (i, i, 256, 23);
-      do_test (i, i, 256, 0);
+      do_test (&json_ctx, 0, i, 256, 23);
+      do_test (&json_ctx, 0, i, 256, 0);
+      do_test (&json_ctx, i, i, 256, 23);
+      do_test (&json_ctx, i, i, 256, 0);
 #endif
     }
   for (i = 1; i < 8; ++i)
     {
-      do_test (i, i << 5, 192, 23);
-      do_test (i, i << 5, 192, 0);
-      do_test (i, i << 5, 256, 23);
-      do_test (i, i << 5, 256, 0);
-      do_test (i, i << 5, 512, 23);
-      do_test (i, i << 5, 512, 0);
+      do_test (&json_ctx, i, i << 5, 192, 23);
+      do_test (&json_ctx, i, i << 5, 192, 0);
+      do_test (&json_ctx, i, i << 5, 256, 23);
+      do_test (&json_ctx, i, i << 5, 256, 0);
+      do_test (&json_ctx, i, i << 5, 512, 23);
+      do_test (&json_ctx, i, i << 5, 512, 0);
+
+      do_test (&json_ctx, getpagesize () - 15, i << 5, 256, 23);
     }
   for (i = 1; i < 32; ++i)
     {
-      do_test (0, i, i + 1, 23);
-      do_test (0, i, i + 1, 0);
-      do_test (i, i, i + 1, 23);
-      do_test (i, i, i + 1, 0);
-      do_test (0, i, i - 1, 23);
-      do_test (0, i, i - 1, 0);
-      do_test (i, i, i - 1, 23);
-      do_test (i, i, i - 1, 0);
+      do_test (&json_ctx, 0, i, i + 1, 23);
+      do_test (&json_ctx, 0, i, i + 1, 0);
+      do_test (&json_ctx, i, i, i + 1, 23);
+      do_test (&json_ctx, i, i, i + 1, 0);
+      do_test (&json_ctx, 0, i, i - 1, 23);
+      do_test (&json_ctx, 0, i, i - 1, 0);
+      do_test (&json_ctx, i, i, i - 1, 23);
+      do_test (&json_ctx, i, i, i - 1, 0);
+
+      do_test (&json_ctx, getpagesize () - 15, i, i - 1, 23);
+      do_test (&json_ctx, getpagesize () - 15, i, i - 1, 0);
+
+      do_test (&json_ctx, getpagesize () - 15, i, i + 1, 23);
+      do_test (&json_ctx, getpagesize () - 15, i, i + 1, 0);
 #ifdef USE_AS_MEMRCHR
       /* Also test the position close to the beginning for memrchr.  */
-      do_test (0, 1, i + 1, 23);
-      do_test (0, 2, i + 1, 0);
+      do_test (&json_ctx, 0, 1, i + 1, 23);
+      do_test (&json_ctx, 0, 2, i + 1, 0);
 #endif
     }
 
+  json_array_end (&json_ctx);
+  json_attr_object_end (&json_ctx);
+  json_attr_object_end (&json_ctx);
+  json_document_end (&json_ctx);
+
   return ret;
 }