Original Post
I'm trying to optimize my raytracer, so I started to measure the execution time of my methods. I've noticed that there's a big difference in execution time depending on where do I declare the variables. Take a look:
This took 3.3426 sec to execute.
This took 0.0000014 sec to execute.
Where this difference come from?
Vector v(1, 1, 1);for(unsigned int i=0;i<100000000;i++){ v.normalize();}This took 3.3426 sec to execute.
for(unsigned int i=0;i<100000000;i++){ Vector v(1, 1, 1); v.normalize();}This took 0.0000014 sec to execute.
Where this difference come from?