summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Ball <nullspoon@oper.io>2016-11-28 15:01:59 -0700
committerAaron Ball <nullspoon@oper.io>2016-11-28 15:01:59 -0700
commit7be0c13884b2a220e1d90a4ef6ce1c3f2690dcbe (patch)
tree1531f206180cbd03c5b20052dde366a5533928a0
parentffa29bb57ff5555d2aab7d2b1750e8ff10c99d73 (diff)
downloadpalindrome_finder-7be0c13884b2a220e1d90a4ef6ce1c3f2690dcbe.tar.gz
palindrome_finder-7be0c13884b2a220e1d90a4ef6ce1c3f2690dcbe.tar.xz
Fixed palindrome search timer
Was miscalculating nanosecond duration. This fixes that.
-rw-r--r--src/main.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/main.c b/src/main.c
index 479c48b..69f297e 100644
--- a/src/main.c
+++ b/src/main.c
@@ -160,11 +160,11 @@ int main(int argc, char *argv[]) {
free(data);
- // Calculate runtime
- long int secs = stop.tv_sec - start.tv_sec;
- long int nano = stop.tv_nsec - start.tv_nsec;
+ // Calculate search time
+ double timestart = start.tv_sec + (1.0e-9 * start.tv_nsec);
+ double timestop = stop.tv_sec + (1.0e-9 * stop.tv_nsec);
// Print runtime message
- printf("Palindrome search took %ld.%ld seconds\n", secs, nano / 10000);
+ printf("Palindrome search took %.5f seconds\n", timestop - timestart);
return 0;
}

Generated by cgit