From 351c775e0837ca4009ea45fd02d3c5ded43af38b Mon Sep 17 00:00:00 2001 From: Aaron Ball Date: Mon, 28 Nov 2016 14:16:51 -0700 Subject: Added run time timer for actual palidrome search op --- src/main.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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 #include +#include // // 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; } -- cgit v1.2.3