I did a little speed testing in C ++ (MSVS) and got a weird result. I tested the speed of using one for a loop against multiple nested loops. Here is the code:
double testX = 0;
for( int i = 0; i < 27000000; i++ ){
testX += 1;
}
for( int x = 0; x < 300; x++ ){
for( int y = 0; y < 300; y++ ){
for( int z = 0; z < 300; z++ ){
testX += 1;
}
}
}
As you can see, the speed difference is pretty obvious. I have run this many times and this is the average time I see (they are synchronized using glfwGetTime ()).
So my question is: why? Is my testing method inadequate? Am I using too few loops? I tried to find google, and the only similar question I could find related its problem with caching coherency, but since they are empty for loops, I did not think that this would really have an effect.
Any help is determined :)
:. , , , ... , () . . , , .
, ( /, ).