summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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