Quote:Original post by EvilDecl81Quote:
myVec3 v1(1.5f, 2.0f, 1.0f);
myVec3 v2(5.0f, 4.0f, 1.0f), fd;
D3DXVECTOR3 v3(1.5f, 2.0f, 1.0f), v4(5.0f, 4.0f, 1.0f), v5;
unsigned long i1 = timeGetTime();
for(unsigned int i = 0; i<100000000; i++) {
MATHMyVec3Cross(&v1, &v2, &fd);
//MATHMyVec3Cross2(&v1, &v2, &fd);
//D3DXVec3Cross(&v5, &v4, &v3);
}
unsigned long i2 = timeGetTime();
i2-=i1;
HEY, COMPILE ON VC++ 2003!!
Quite frankly, I'm surprised you got any real meaningful data. VC should have removed the loop since it doesn't do anything. Unless you are running a debug build. You can't just put a function in a loop and call it a million times - you have to do non-trivial operation the compiler can't just optimize away.
Cross product is also a very uninteresting test. Since the call goes through a dispatch table, you always have a small amount of overhead for any math routine. This shows up in very simple math operations. My suggestion: Try beating the Matrix Multiply.
Does it really optimise it away? I actually think it will not do that, as it is working on variables outside of the loop body. If it would optimise this loop away, the total behaviour of the application which expects the variable to be changed, changes. Anyone can say something about this?