From 70f03ebd34e1ac52e7fb3712fe7e631181c6bf79 Mon Sep 17 00:00:00 2001 From: Niranjan Date: Thu, 13 Apr 2023 22:25:31 +0530 Subject: [PATCH] feat: Record time duration of function execution --- math/fibonacci.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/math/fibonacci.c b/math/fibonacci.c index 53595008c1..35886ba1db 100644 --- a/math/fibonacci.c +++ b/math/fibonacci.c @@ -14,6 +14,7 @@ #include /// for errno - to determine whether there is an using strtol() #include /// for input, output #include /// for exit() - to exit the program +#include /// to calculate time taken by fib() /** * @brief Determines the nth Fibonacci term * @param number - n in "nth term" and it can't be negative as well as zero @@ -80,7 +81,7 @@ int getInput(void) break; } - printf("\nEntered digit: %d\n", num); + printf("\nEntered digit: %d (it might take sometime)\n", num); return num; } @@ -112,7 +113,12 @@ int main() "than or equal to 48 ) is entered.\n"); int number = getInput(); + clock_t start, end; - printf("Fibonacci element %d is %u\n", number, fib(number)); + start = clock(); + printf("Fibonacci element %d is %u ", number, fib(number)); + end = clock(); + + printf("in %.3f seconds.\n", ((double)(end - start)) / CLOCKS_PER_SEC ); return 0; }