From 6ec1f403554bddef5d201402ab0a33069039144a Mon Sep 17 00:00:00 2001 From: Laurent Mazet Date: Sun, 28 Sep 2025 23:32:21 +0200 Subject: [PATCH] add features for histogram --- stat.c | 2 +- test.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 52 insertions(+), 2 deletions(-) diff --git a/stat.c b/stat.c index f28730e..f39d441 100644 --- a/stat.c +++ b/stat.c @@ -91,7 +91,7 @@ void compute_statistics (int64_t *points, int nb, int bins) } hist[bins - 1]++; - printf ("Histogram\n"); + printf ("Histogram (%d)\n", nb); for (int i = 0; i < bins; i++) { printf (" [%.2lf - %.2lf] = %d\n", min + i * gap, min + (i + 1) * gap, hist[i]); } diff --git a/test.c b/test.c index 4c10ee9..dce0ef4 100644 --- a/test.c +++ b/test.c @@ -12,9 +12,11 @@ char *progname = NULL; char *version = "1.1"; -int nb = 1000; +double abe_per = 0; int do_stat = 0; +int excl_first = 0; int hist_bin = 10; +int nb = 1000; char *output = NULL; extern char *message; @@ -25,7 +27,9 @@ int usage (int ret) { FILE *fd = ret ? stderr : stdout; fprintf (fd, "usage: %s [-b int] [-h] [-n int] [-o file] [-s]\n", progname); + fprintf (fd, " -a: avoid aberrand valies (%g%%)\n", abe_per); fprintf (fd, " -b: nb bins for histogram (%d)\n", hist_bin); + fprintf (fd, " -e: exclude %d first tests\n", excl_first); fprintf (fd, " -h: help message\n"); fprintf (fd, " -n: nb measurements (%d)\n", nb); fprintf (fd, " -o: output raw data (%s)\n", (output) ? output : "none"); @@ -60,6 +64,14 @@ int main (int argc, char *argv[]) } char c = arg[1]; switch (c) { + case 'a': + arg = (arg[2]) ? arg + 2 : (--argc > 0) ? *(++argv) : NULL; + if (arg == NULL) { + fprintf (stderr, "%s: no aberrant percent specified\n", progname); + return usage (1); + } + abe_per = strtod (arg, NULL); + break; case 'b': arg = (arg[2]) ? arg + 2 : (--argc > 0) ? *(++argv) : NULL; if (arg == NULL) { @@ -68,6 +80,14 @@ int main (int argc, char *argv[]) } hist_bin = atoi (arg); break; + case 'e': + arg = (arg[2]) ? arg + 2 : (--argc > 0) ? *(++argv) : NULL; + if (arg == NULL) { + fprintf (stderr, "%s: no number of first to exclude specified\n", progname); + return usage (1); + } + excl_first = atoi (arg); + break; case 'n': arg = (arg[2]) ? arg + 2 : (--argc > 0) ? *(++argv) : NULL; if (arg == NULL) { @@ -122,6 +142,36 @@ int main (int argc, char *argv[]) } if (do_stat) { + + if (excl_first) { + for (int i = 0; i < nb - excl_first; i++) { + buffer[i] = buffer[i + excl_first]; + } + nb -= excl_first; + } + + if (abe_per != 0) { + for (int j = 1; j < nb - 1; j++) { + int change_done = 0; + for (int i = 1; i < nb - 1; i++) { + if (buffer[i + 1] < buffer[i]) { + int64_t tmp = buffer[i]; + buffer[i] = buffer[i + 1]; + buffer[i + 1] = tmp; + change_done = 1; + } + } + if (!change_done) { + break; + } + } + int n = nb * abe_per / 100; + for (int i = 0; i < nb - n; i++) { + buffer[i] = buffer[i - n / 2]; + } + nb -= n; + } + char unit[32] = { 0 }; switch (sec_unit) { case sec_e : strcpy (unit, "second"); break; -- 2.30.2