public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 1/2] benchtests: Use JSON for bench-rawmemchr output
@ 2021-05-12 14:27 Matheus Castanho
  2021-05-12 14:27 ` [PATCH 2/2] powerpc: Add optimized rawmemchr for POWER10 Matheus Castanho
  2021-05-12 18:57 ` [PATCH 1/2] benchtests: Use JSON for bench-rawmemchr output Lucas A. M. Magalhaes
  0 siblings, 2 replies; 9+ messages in thread
From: Matheus Castanho @ 2021-05-12 14:27 UTC (permalink / raw)
  To: libc-alpha

Convert the output of benchtests/bench-rawmemchr to JSON like other string
benchmarks.  This makes the output more parseable and allows usage of
compare_strings.py, for example.
---
 benchtests/bench-rawmemchr.c | 54 ++++++++++++++++++++++++++----------
 1 file changed, 39 insertions(+), 15 deletions(-)

diff --git a/benchtests/bench-rawmemchr.c b/benchtests/bench-rawmemchr.c
index 93b4a1ea38..80286b04b0 100644
--- a/benchtests/bench-rawmemchr.c
+++ b/benchtests/bench-rawmemchr.c
@@ -23,6 +23,8 @@
 #define TEST_NAME "rawmemchr"
 #include "bench-string.h"
 
+#include "json-lib.h"
+
 typedef char *(*proto_t) (const char *, int);
 
 char *
@@ -37,7 +39,7 @@ IMPL (rawmemchr, 1)
 IMPL (generic_rawmemchr, 0)
 
 static void
-do_one_test (impl_t *impl, const char *s, int c, char *exp_res)
+do_one_test (json_ctx_t *json_ctx, impl_t *impl, const char *s, int c, char *exp_res)
 {
   size_t i, iters = INNER_LOOP_ITERS_LARGE * 4;
   timing_t start, stop, cur;
@@ -59,11 +61,11 @@ do_one_test (impl_t *impl, const char *s, int c, char *exp_res)
 
   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;
   char *result;
@@ -86,39 +88,61 @@ do_test (size_t align, size_t pos, size_t len, int seek_char)
   buf1[align + len] = -seek_char;
   result = (char *) (buf1 + align + pos);
 
-  printf ("Length %4zd, alignment %2zd:", pos, align);
+  json_element_object_begin (json_ctx);
+  json_attr_uint (json_ctx, "length", pos);
+  json_attr_uint (json_ctx, "alignment", align);
+  json_attr_uint (json_ctx, "char", seek_char);
+  json_array_begin (json_ctx, "timings");
 
   FOR_EACH_IMPL (impl, 0)
-    do_one_test (impl, (char *) (buf1 + align), seek_char, result);
+    do_one_test (json_ctx, impl, (char *) (buf1 + align), seek_char, result);
 
-  putchar ('\n');
+  json_array_end (json_ctx);
+  json_element_object_end (json_ctx);
 }
 
 int
 test_main (void)
 {
+  json_ctx_t json_ctx;
   size_t i;
 
   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 < 7; ++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);
     }
   for (i = 1; i < 32; ++i)
     {
-      do_test (0, i, i + 1, 23);
-      do_test (0, i, i + 1, 0);
+      do_test (&json_ctx, 0, i, i + 1, 23);
+      do_test (&json_ctx, 0, i, i + 1, 0);
     }
 
+  json_array_end (&json_ctx);
+  json_attr_object_end (&json_ctx);
+  json_attr_object_end (&json_ctx);
+  json_document_end (&json_ctx);
+
   return ret;
 }
 
-- 
2.31.1


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2021-05-17 14:22 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-12 14:27 [PATCH 1/2] benchtests: Use JSON for bench-rawmemchr output Matheus Castanho
2021-05-12 14:27 ` [PATCH 2/2] powerpc: Add optimized rawmemchr for POWER10 Matheus Castanho
2021-05-13 13:32   ` Raphael M Zinsly
2021-05-14 13:30     ` Matheus Castanho
2021-05-14 13:53       ` Raphael M Zinsly
2021-05-13 19:57   ` Lucas A. M. Magalhaes
2021-05-17 14:05   ` Matheus Castanho
2021-05-12 18:57 ` [PATCH 1/2] benchtests: Use JSON for bench-rawmemchr output Lucas A. M. Magalhaes
2021-05-17 14:22   ` Matheus Castanho

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).