diff options
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 12 |
1 files changed, 12 insertions, 0 deletions
@@ -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; } |