summaryrefslogtreecommitdiff
path: root/bench.c
diff options
context:
space:
mode:
authorBobby Bingham <koorogi@koorogi.info>2014-06-21 11:36:20 -0500
committerBobby Bingham <koorogi@koorogi.info>2014-06-21 11:36:20 -0500
commitdc93b6db9202481ed9b587e66ce4345fdcdfafe8 (patch)
tree721c75d9459656525e8897892a260a2d7ff7a120 /bench.c
parentf305d9d704dd76385941414287f5124d8c35d8b5 (diff)
validate that sorter succeeded in sorting the input
Diffstat (limited to 'bench.c')
-rw-r--r--bench.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/bench.c b/bench.c
index a51ee99..19f7204 100644
--- a/bench.c
+++ b/bench.c
@@ -37,6 +37,16 @@ static inline unsigned long timediff_ms(struct timespec *start, struct timespec
return 1000 * (stop->tv_sec - start->tv_sec) + (stop->tv_nsec - start->tv_nsec) / 1000000;
}
+static inline void assert_sorted(int *buffer, size_t size)
+{
+ if (!size) return;
+ int prev = buffer[0];
+ for (size_t i = 1; i < size; i++) {
+ if (prev > buffer[i]) abort();
+ prev = buffer[i];
+ }
+}
+
int main()
{
struct timespec start, stop;
@@ -61,6 +71,7 @@ int main()
if (clock_gettime(CLOCK_THREAD_CPUTIME_ID, &stop)) abort();
printf("%*lu %*lu ", CMP_WIDTH, comparisons, MS_WIDTH, timediff_ms(&start, &stop));
+ assert_sorted(buffer, size);
}
printf(" %*zu\n", SIZE_WIDTH, size);
}