[Resolved?] float functions are faster than if() -
RSX - 12.09.2010
Here's the code, which one is faster? I need quite fast check and it's with floats of course.
or :
pawn Code:
if(X>0 && Y>0)
else if(X<0 && Y<0)
Re: Faster :Triple check or check with * -
LarzI - 12.09.2010
They're not even doing the same thing, how can you find out which one's faster then?
Re: [Resolved?] float functions are faster than if() -
RSX - 12.09.2010
Woups. Now they're checking if X*Y is more than 0, one's with just doing X*Y other with checking if X and Y is >0 or if X and Y is <0
Btw, f that spammer above me.
Re: Faster :Triple check or check with * -
LarzI - 12.09.2010
Let me just show you one thing..
X = 3, Y = 4
pawn Code:
if(3*4<0)
if(12<0) //is the outcome. This will return false.
pawn Code:
if(X>0 && Y>0)
else if(X<0 && Y<0)
X = 3, Y = 4
pawn Code:
if(3>0 && 4>0) //will return true
else if(3<0 && 4<0) //will return false
These are two completely different codes. You can't compare speed with that.
Re: Faster :Triple check or check with * -
RSX - 12.09.2010
Okay. you seem to miss the concept. If wanted thing is true, (BTW, by last post you could have understood that i meant > instead of copying my mistake) then one is called, so that
if(3>0 && 4>0) //will return true - YES. And effect is equal to next one.
else if(3<0 && 4<0) //will return false
if(3*4>0) - This too will be called, so both scripts check same thing. They pass only when x and y is both positive or negative making result positive. GOT IT? For you i can note that triple check means that the second example at worst does 3 checks in case of X and Y being < 0 :
if(X>0 && Y>0) - evaluates false and doesn't even go to Y.
if(X<0 && Y<0) - evaluates true with 2 checks.
Re: Faster :Triple check or check with * -
kc - 12.09.2010
Why not test it?
Y_Less has what you would need to do so near the top of
this.
Re:[Resolved?] float functions are faster than if() -
RSX - 12.09.2010
I have already tested once, but great thanks, i didn't expect results at all. 4 Check variant failed in every type (x>0 y>0; x<0 y>0; x<0 y<0; x>0 y<0;)
pawn Code:
#include <a_samp>
//#define CODE_1 printf("%d", 42);
//#define CODE_2 new str[4]; format(str, sizeof (str), "%d", 42); print(str);
#define ITERATIONS (1000000)
public OnFilterScriptInit() Test();
Test()
{
new
t0,
t1,
t2,
i,j,
Float:x=0.3525,Float:y=0.5435431;
for (j = 0; j <10;j++)
{
t0 = GetTickCount();
for (i = 0; i < ITERATIONS; i++)
{
if(x*y>0) continue;
}
t1 = GetTickCount();
for (i = 0; i < ITERATIONS; i++)
{
if(x>0 && y>0) continue;
else if(x<0 && y<0) continue;
}
t2 = GetTickCount();
printf("Time 1: %04d, time 2: %04d", t1 - t0, t2 - t1);
}
}
X*Y>0 was 200ms faster :O.
Sorry for my mistakes, i'm dealing with quite problematic code right now, which could change a lot. Only problem - i'm not going to let noobs to handle it. Really only compiled special clause scripts will be relesed for everyone.
Test result continue.. even more wierd :
pawn Code:
if(Prev_X<x) Dir=floatround(Float:y,floatround_ceil)+1;
Faster than :
pawn Code:
if(Prev_X<x) if(y>0) Dir=false; else Dir=true;