The below code in unix takes ~9s reported by time command.
int main()
{
double u = 0;
double v = 0;
double w = 0;
int i;
for (i = 0;i < 1000000000;++i) {
v *= w;
u += v;
}
printf("%lf\n",u);
}
I don’t understand why the execution times almost double when i change v *= w;withv *= u;
When you change
v *= wtov *= uthen there is an inter-dependency between the 2 statements. Hence, the first statement has to be completed before executingu += vwhich could be the reason for the increased performance as the compiler can’t parallelize the execution.