Hey guys so i have to time how long each of my functions take to run and am stuck i know i have to use the time.h but i don't know how to start and end it heres my code i have to time the fibonacci number using recursion and iteratively. I have to time them each to see which one is faster to calculate odd number from 1-15. I have all the code written just need to implement the timer
#include <iostream>
#include <time.h>
usingnamespace std;
int recFib(int n);
int recFib(int n){
if (n<2) {
return 1;
}
else {
return (recFib(n-2) + recFib(n-1));
}
}
int itFib(int n);
int itFib(int n){
int m=0;
int k=1;
int num;
for (int i=0;i<=n;i++) {
num=m+k;
m=k;
k=num;
}
return m;
}
int main() {
int result, result2;
cout << "Iterative Function" << endl;
// have to time this
for(int i=1;i<=15;i=i+2){
result= itFib(i);
cout << result << endl;
}
cout << endl;
cout << "Recursion Function"
// have to time this
for (int i=1;i<=15;i=i+2) {
result = recFib(i);
cout << result2 << endl
}
return 0;
}