summaryrefslogtreecommitdiff
path: root/counts.c
diff options
context:
space:
mode:
authorBobby Bingham <koorogi@koorogi.info>2014-10-29 20:32:33 -0500
committerBobby Bingham <koorogi@koorogi.info>2014-10-29 20:32:33 -0500
commit8a27889d505b07d91ecd03ad1cfeb818b9b440f7 (patch)
tree733e342e932f67aa56b9554b6d901fea129ad578 /counts.c
parent40a6ba5c0a5f544bed9c11dc30b751e05a435b1e (diff)
Add instrumentation
Track the number of comparisons, swaps, and rotations performed in each part of the sorting algorithm.
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);
+ }
+}