diff options
author | Aaron Ball <nullspoon@oper.io> | 2016-11-28 14:16:51 -0700 |
---|---|---|
committer | Aaron Ball <nullspoon@oper.io> | 2016-11-28 14:16:51 -0700 |
commit | 351c775e0837ca4009ea45fd02d3c5ded43af38b (patch) | |
tree | f4a8f85df0f64618599ed6e6d5e4afcf3dcedda9 | |
parent | 6aeb106de30e9c5438891732f9dbebdee1d19d93 (diff) | |
download | palindrome_finder-351c775e0837ca4009ea45fd02d3c5ded43af38b.tar.gz palindrome_finder-351c775e0837ca4009ea45fd02d3c5ded43af38b.tar.xz |
Added run time timer for actual palidrome search op
-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; } |