add features for histogram
authorLaurent Mazet <mazet@softndesign.org>
Sun, 28 Sep 2025 21:32:21 +0000 (23:32 +0200)
committerLaurent Mazet <mazet@softndesign.org>
Sun, 28 Sep 2025 21:32:21 +0000 (23:32 +0200)
stat.c
test.c

diff --git a/stat.c b/stat.c
index f28730efe3298eae3e86a8fc9417b6eb4f1192f9..f39d441883857e92773e86d83feed91e164bc764 100644 (file)
--- 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 4c10ee97bd604efb7da81c03eb8aead8b42f8e18..dce0ef46a14f5670355ea1baab54c1d281424a41 100644 (file)
--- a/test.c
+++ b/test.c
 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;