I have to run a piece of code that manages a video stream from camera. I am trying to boost it, and I realized a weird C++ behaviour. (I have to admit I am realizing I do not know C++)

The first piece of code run faster than the seconds, why? It might be possible that the stack is almost full?

Faster version

```
double* temp = new double[N];
for(int i = 0; i < N; i++){
temp[i] = operation(x[i],y[i]);
res = res + (temp[i]*temp[i])*coeff[i];
}
```

Slower version1

```
double temp;
for(int i = 0; i < N; i++){
temp = operation(x[i],y[i]);
res = res + (temp*temp)*coeff[i];
}
```

Slower version2

```
for(int i = 0; i < N; i++){
double temp = operation(x[i],y[i]);
res = res + (temp*temp)*coeff[i];
}
```

**EDIT** I realized the compiler was optimizing the product between elemnts of **coeff** and **temp**. I beg your pardon for the unuseful question. I will delete this post.