diff options
author | Will Newton <will.newton@linaro.org> | 2014-04-08 10:18:16 +0100 |
---|---|---|
committer | Will Newton <will.newton@linaro.org> | 2014-04-11 16:05:03 +0100 |
commit | 970c602aa60bb29845c445c18d7b20f7c4552b78 (patch) | |
tree | 734a1f22c1c51cf3cd9d8c94e42a0f0e4a41ab5a /benchtests/bench-skeleton.c | |
parent | 36875b06e0ed7f137190b9228bef553adfc338ba (diff) | |
download | glibc-970c602aa60bb29845c445c18d7b20f7c4552b78.tar glibc-970c602aa60bb29845c445c18d7b20f7c4552b78.tar.gz glibc-970c602aa60bb29845c445c18d7b20f7c4552b78.tar.bz2 glibc-970c602aa60bb29845c445c18d7b20f7c4552b78.zip |
benchtests: Improve readability of JSON output
Add a small library to print JSON values and use it to improve the
readability of the benchmark output and the readability of the
benchmark code.
ChangeLog:
2014-04-11 Will Newton <will.newton@linaro.org>
* benchtests/Makefile (extra-objs): Add json-lib.o.
(bench-func): Tidy up JSON output.
* benchtests/bench-skeleton.c: Include json-lib.h.
(main): Use JSON library functions to do output of
benchmark results.
* benchtests/bench-timing-type.c (main): Output the
timing type simply, leaving formatting to the user.
* benchtests/json-lib.c: New file.
* benchtests/json-lib.h: Likewise.
Diffstat (limited to 'benchtests/bench-skeleton.c')
-rw-r--r-- | benchtests/bench-skeleton.c | 39 |
1 files changed, 22 insertions, 17 deletions
diff --git a/benchtests/bench-skeleton.c b/benchtests/bench-skeleton.c index 0c7d7440cc..29d6bda809 100644 --- a/benchtests/bench-skeleton.c +++ b/benchtests/bench-skeleton.c @@ -23,6 +23,7 @@ #include <time.h> #include <inttypes.h> #include "bench-timing.h" +#include "json-lib.h" volatile unsigned int dontoptimize = 0; @@ -50,6 +51,7 @@ main (int argc, char **argv) struct timespec runtime; timing_t start, end; bool detailed = false; + json_ctx_t json_ctx; if (argc == 2 && !strcmp (argv[1], "-d")) detailed = true; @@ -64,13 +66,13 @@ main (int argc, char **argv) iters = 1000 * res; + json_init (&json_ctx, 2, stdout); + /* Begin function. */ - printf ("\"%s\": {\n", FUNCNAME); + json_attr_object_begin (&json_ctx, FUNCNAME); for (int v = 0; v < NUM_VARIANTS; v++) { - if (v) - putc (',', stdout); /* Run for approximately DURATION seconds. */ clock_gettime (CLOCK_MONOTONIC_RAW, &runtime); runtime.tv_sec += DURATION; @@ -119,28 +121,31 @@ main (int argc, char **argv) d_total_s = total; d_iters = iters; - printf ("\"%s\": {\n", VARIANT (v)); - printf ("\"duration\": %g, \"iterations\": %g, " - "\"max\": %g, \"min\": %g, \"mean\": %g\n", - d_total_s, d_total_i, max / d_iters, min / d_iters, - d_total_s / d_total_i); + /* Begin variant. */ + json_attr_object_begin (&json_ctx, VARIANT (v)); + + json_attr_double (&json_ctx, "duration", d_total_s); + json_attr_double (&json_ctx, "iterations", d_total_i); + json_attr_double (&json_ctx, "max", max / d_iters); + json_attr_double (&json_ctx, "min", min / d_iters); + json_attr_double (&json_ctx, "mean", d_total_s / d_total_i); if (detailed) { - printf (",\n\"timings\": ["); + json_array_begin (&json_ctx, "timings"); + for (int i = 0; i < NUM_SAMPLES (v); i++) - { - if (i > 0) - putc (',', stdout); - printf ("%g", RESULT (v, i)); - } - puts ("]"); + json_element_double (&json_ctx, RESULT (v, i)); + + json_array_end (&json_ctx); } - puts ("}"); + + /* End variant. */ + json_attr_object_end (&json_ctx); } /* End function. */ - puts ("}"); + json_attr_object_end (&json_ctx); return 0; } |