Negative_3
n00b
- Joined
- Apr 14, 2008
- Messages
- 45
Here is a little C program that I am compiling with Visual Studio 2005:
This program just tells you how long it takes to run some random code. Notice that there are two things commented out (the green text). One would expect that uncommenting these things would slow the program down slightly, as it would have more to do.
First run the program and see how long it takes. Then uncomment the "+ 3.1" and run it again. It was expected to be slightly slower, but instead it is MANY TIMES FASTER! Can anyone explain this?
Next, uncomment the inline ASM block and run the program again. It was expected to be slightly slower, but instead it is SLIGHTLY FASTER! A random ASM statement that does NOTHING actually speeds the program up? Can anyone explain this?
Here is the code in non picture format:
This program just tells you how long it takes to run some random code. Notice that there are two things commented out (the green text). One would expect that uncommenting these things would slow the program down slightly, as it would have more to do.
First run the program and see how long it takes. Then uncomment the "+ 3.1" and run it again. It was expected to be slightly slower, but instead it is MANY TIMES FASTER! Can anyone explain this?
Next, uncomment the inline ASM block and run the program again. It was expected to be slightly slower, but instead it is SLIGHTLY FASTER! A random ASM statement that does NOTHING actually speeds the program up? Can anyone explain this?
Here is the code in non picture format:
Code:
#include <stdio.h>
#include <windows.h>
void main(void)
{
int i,j;
unsigned int startTime;
float a,b,c,x,y,z,vx=1,ux=-1,wx=-3,vy=3,uy=4,wy=5,vz=6,uz=7,wz=8,denominator;
__declspec(align(16))float f1[4]={0,0,0,0};
printf("Starting...\n");
startTime=GetTickCount();
for(j=0;j<10000;j++)
{
for(i=0;i<10000;i++)
{
x=(float) i;
y=x+1;
z=y+1;
//__asm
//{
// movaps xmm0,f1
//}
denominator= -uz*vy*wx + uy*vz*wx + uz*vx*wy - ux*vz*wy - uy*vx*wz + ux*vy*wz /*+ 3.1*/;
a= (uz*wy*x - uy*wz*x - uz*wx*y + ux*wz*y + uy*wx*z - ux*wy*z)/denominator;
b= (vz*wy*x - vy*wz*x - vz*wx*y + vx*wz*y + vy*wx*z - vx*wy*z)/denominator;
c= (uz*vy*x - uy*vz*x - uz*vx*y + ux*vz*y + uy*vx*z - ux*vy*z)/denominator;
}
}
printf("Number Of Milliseconds: %u\n\n",GetTickCount()-startTime,a,b,c);
}