summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Ball <nullspoon@oper.io>2016-11-28 14:17:17 -0700
committerAaron Ball <nullspoon@oper.io>2016-11-28 14:17:21 -0700
commitffa29bb57ff5555d2aab7d2b1750e8ff10c99d73 (patch)
treef4a8f85df0f64618599ed6e6d5e4afcf3dcedda9
parent6aeb106de30e9c5438891732f9dbebdee1d19d93 (diff)
parent351c775e0837ca4009ea45fd02d3c5ded43af38b (diff)
downloadpalindrome_finder-ffa29bb57ff5555d2aab7d2b1750e8ff10c99d73.tar.gz
palindrome_finder-ffa29bb57ff5555d2aab7d2b1750e8ff10c99d73.tar.xz
Merge branch 'print-runtime'
Signed-off-by: Aaron Ball <nullspoon@oper.io>
-rw-r--r--src/main.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/main.c b/src/main.c
index 23cd9d7..479c48b 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1,5 +1,6 @@
#include <stdio.h>
#include <stdlib.h>
+#include <time.h>
//
// Compare the whole thing by passing 0 as end
@@ -117,6 +118,7 @@ int main(int argc, char *argv[]) {
return 1;
}
+ struct timespec start, stop;
FILE *f = fopen(argv[1], "r");
// If the file can't be opened, try using the passed value as a palindrome
@@ -152,7 +154,17 @@ int main(int argc, char *argv[]) {
printf("Searching for palindromes\n");
+ clock_gettime(CLOCK_MONOTONIC_RAW, &start);
find_largest_palindromes(data);
+ clock_gettime(CLOCK_MONOTONIC_RAW, &stop);
+
free(data);
+
+ // Calculate runtime
+ long int secs = stop.tv_sec - start.tv_sec;
+ long int nano = stop.tv_nsec - start.tv_nsec;
+ // Print runtime message
+ printf("Palindrome search took %ld.%ld seconds\n", secs, nano / 10000);
+
return 0;
}

Generated by cgit