summaryrefslogtreecommitdiff
path: root/counts.c
diff options
context:
space:
mode:
Diffstat (limited to 'counts.c')
-rw-r--r--counts.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/counts.c b/counts.c
new file mode 100644
index 0000000..d1f3910
--- /dev/null
+++ b/counts.c
@@ -0,0 +1,38 @@
+#include <stdint.h>
+#include <stdio.h>
+
+#include "counts.h"
+
+struct counts counts[MAX_COUNTS];
+
+static void clear(struct counts *c)
+{
+ *c = (struct counts) {0};
+}
+
+void clear_all_counts(void)
+{
+ for (int i = 0; i < MAX_COUNTS; i++)
+ clear(counts+i);
+}
+
+void clear_accumulator(void)
+{
+ clear(counts);
+}
+
+void add_counts(struct counts *target, struct counts *snapshot)
+{
+ target->compare += counts[CURRENT].compare - snapshot->compare;
+ target->rotate += counts[CURRENT].rotate - snapshot->rotate;
+ target->swap += counts[CURRENT].swap - snapshot->swap;
+}
+
+void print_counts(void)
+{
+ char *labels[] = {"total", "sortnet", "overlap", "merge", "move buffer", "distribute"};
+ for (int i = 0; i < MAX_COUNTS; i++) {
+ const struct counts *c = counts+i;
+ dprintf(42, "%12s: %10lu cmp, %10lu swap, %10lu rotate\n", labels[i], c->compare, c->swap, c->rotate);
+ }
+}