Hi,
I want to calculate execution time for a program computing fibonacci number in C++. I have programmed two functions (one using recursion and other using divide and conquer huristic) to compute fibonnaci number for (n=4,8,16,32,64 ). Now i want to compare these two methods. Though i have used following method to compute execution time but it is not precise as yielding 0 ticker time for n=4,8,16 in both the cases
[code=c]
double execClock(clock _t c1,clock_t c2)
{
double t=clock1-clock2;
double tim=(t*10)/CLOCKS_PER_SEC;
return tim;
}
[/code]
Is there anyother method which is more accurate for lower values of n, i am working in Inet/Windows XP/Dev C++ environment?
While following using recursive method
[code=c]
int fib(int n)
{
if (n <= 1)
return n;
else
return fib(n-1) + fib (n-2);
}
[/code]
i can not compute fibonacci number for n=64, just system gets hanged, CPU usage reaches to 97% for the application, it seems it has struk in the computation
With Regards
Jianyi
I want to calculate execution time for a program computing fibonacci number in C++. I have programmed two functions (one using recursion and other using divide and conquer huristic) to compute fibonnaci number for (n=4,8,16,32,64 ). Now i want to compare these two methods. Though i have used following method to compute execution time but it is not precise as yielding 0 ticker time for n=4,8,16 in both the cases
[code=c]
double execClock(clock _t c1,clock_t c2)
{
double t=clock1-clock2;
double tim=(t*10)/CLOCKS_PER_SEC;
return tim;
}
[/code]
Is there anyother method which is more accurate for lower values of n, i am working in Inet/Windows XP/Dev C++ environment?
While following using recursive method
[code=c]
int fib(int n)
{
if (n <= 1)
return n;
else
return fib(n-1) + fib (n-2);
}
[/code]
i can not compute fibonacci number for n=64, just system gets hanged, CPU usage reaches to 97% for the application, it seems it has struk in the computation
With Regards
Jianyi
Comment