diff mbox series

[1/2] benchtests: Use JSON for bench-rawmemchr output

Message ID 20210512142717.225429-1-msc@linux.ibm.com
State Committed
Commit f4605e611a93891b1fdf8d0f48b3fba0d572f1ad
Headers show
Series [1/2] benchtests: Use JSON for bench-rawmemchr output | expand

Checks

Context Check Description
dj/TryBot-apply_patch success Patch applied to master at the time it was sent

Commit Message

Matheus Castanho May 12, 2021, 2:27 p.m. UTC
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(-)

Comments

Lucas A. M. Magalhaes May 12, 2021, 6:57 p.m. UTC | #1
Hi Matheus, IMO the patches of this patch set are unrelated and should
be submitted separated.

This patch, LGTM.  Test the benchmark and the JSON is well formatted.

Reviewed-by: Lucas A. M. Magalhaes <lamm@linux.ibm.com>

Quoting Matheus Castanho via Libc-alpha (2021-05-12 11:27:16)
> 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"
> +
Ok.

>  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)
>  {
Ok.

>    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);
Ok.

>  }
>  
>  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)
OK.

>  {
>    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");
OK.

>  
>    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);
Ok.

>  
> -  putchar ('\n');
> +  json_array_end (json_ctx);
> +  json_element_object_end (json_ctx);
Ok.

>  }
>  
>  int
>  test_main (void)
>  {
> +  json_ctx_t json_ctx;
Ok.
>    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");
Ok.

>    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");
Ok.

>  
>    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);
>      }
Ok.

>  
> +  json_array_end (&json_ctx);
> +  json_attr_object_end (&json_ctx);
> +  json_attr_object_end (&json_ctx);
> +  json_document_end (&json_ctx);
> +
OK.
>    return ret;
>  }
>  
> -- 
> 2.31.1
>
Matheus Castanho May 17, 2021, 2:22 p.m. UTC | #2
Lucas A. M. Magalhaes <lamm@linux.ibm.com> writes:

> Hi Matheus, IMO the patches of this patch set are unrelated and should
> be submitted separated.

Ok, noted for future submissions.

>
> This patch, LGTM.  Test the benchmark and the JSON is well formatted.
>
> Reviewed-by: Lucas A. M. Magalhaes <lamm@linux.ibm.com>

Committed as f4605e611a93891b1fdf8d0f48b3fba0d572f1ad

Thanks!

--
Matheus Castanho
diff mbox series

Patch

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;
 }