10.07.2010, 10:08
pawn Код:
#define PointToPoint3D2(%1,%2,%3,%4,%5,%6) floatsqroot(floatadd(floatadd(floatmul(floatsub(%1,%4),floatsub(%1,%4)),floatmul(floatsub(%2,%5),floatsub(%2,%5))),floatmul(floatsub(%3,%6),floatsub(%3,%6))))
#define PointToPoint3D4(%1,%2,%3,%4,%5,%6) floatsqroot((%1-%4)*(%1-%4)+(%2-%5)*(%2-%5)+(%3-%6)*(%3-%6))
stock Float:PointToPoint3D3( Float:X1, Float:Y1, Float:Z1, Float:X2, Float:Y2, Float:Z2 )
{
new
Float:X,
Float:Y,
Float:Z;
X = floatsub( X1, X2 );
Y = floatsub( Y1, Y2 );
Z = floatsub( Z1, Z2 );
X = floatmul( X, X );
Y = floatmul( Y, Y );
Z = floatmul( Z, Z );
return floatsqroot( floatadd( floatadd( X, Y ), Z ) );
}
main
{
new i, tick = GetTickCount(), Float:point;
while ( i < 10000000)
{
point = PointToPoint3D3(10.0, 20.0, 30.0, 40.0, 50.0, 60.0);
i++;
}
printf("1 Time %d | %f", GetTickCount() - tick, point);
i = 0;
tick = GetTickCount();
while ( i < 10000000)
{
point = PointToPoint3D2(10.0, 20.0, 30.0, 40.0, 50.0, 60.0);
i++;
}
printf("2 Time %d | %f", GetTickCount() - tick, point);
i = 0;
tick = GetTickCount();
while ( i < 10000000)
{
point = PointToPoint3D4(10.0, 20.0, 30.0, 40.0, 50.0, 60.0);
i++;
}
printf("3 Time %d | %f", GetTickCount() - tick, point);
}
Quote:
1 Time 6282 | 51.961524 2 Time 6433 | 51.961524 3 Time 7436 | 51.961524 |