The following program prints out duration=0.000000000000000000 for some reason. I've read a very similar question The C `clock()` function just returns a zero , but suggestions there didn't help. The loop between which i take time samples is of 100 iterations, and for each one there is a Newton's root finding method with 0.00000001 precision going on, surely it can't take 0 seconds^-20 to compute? Sorry if this questions looks really homework-ish, I'm really noob when it comes to coding. Anybody sees what might be wrong here? Thanks!
double f(...){...}
double h;
double newton (double prev_step_solution, double x)
{
double root=prev_step_solution;
while (((prev_step_solution+h*f(root,x)-root)>0.00000001)
||((prev_step_solution+h*f(root,x)-root)<-0.00000001))
{
root = root-(h*f(root,x)+prev_step_solution-root)/(h*fder(root,x)-1);
}
return root;
}
int main()
{
int i;
double euler [2][101];
h=1/100;
std::clock_t start;
double duration;
start = std::clock();
for (i=1; i<=200; i++)
{
euler [0][i] = h*i;
euler [1][i] = newton(euler[1][i-1],h*(i-1));
}
duration = ((double)( std::clock()-start ))/((double) CLOCKS_PER_SEC);
printf(" euler %.20f \n",(double)duration);
return 0;
}