Some performance questions about control structures
#1

Which usage is better?

1)
a. If (a[id]>0 && a[id]==x)
b. If (a[id] && a[id]==x)
c. If (a[bool:isidset] && a[id]==x)
d. If (a[id]==x)

2)
a. if(!isplayerconnected(i)) continue; if(isplayerinrangeofpoint(i)) {}
b. if(!(isplayerconnected(i) && isplayerinrangeofpoint(i))) continue; else {}
Reply
#2

You are worrying too much, about the wrong stuff, too early. Code first and foremost should be readable for humans, and those "optimisations" are not worth sacrificing readability.
Reply
#3

^ important thing, plus:
Quote:
Originally Posted by godless_phoenix
Посмотреть сообщение
1)
a. If (a[id]>0 && a[id]==x)
b. If (a[id] && a[id]==x)
c. If (a[bool:isidset] && a[id]==x)
d. If (a[id]==x)
d. because,
Those all are just && (AND) conditional, checking the same variable for different condition where you expect both is true, so why need to check the same variable many times?
a. If a[id] is greater than 0 and a[id] is equal to x, the only true condition is when x is also greater than 0
b. If a[id] is not 0 (this is how PAWN do it, a[id] == false is just a[id] == 0 otherwise true for any other value that is not 0), so the same to case a.
c. not sure what is bool:isidset.

Quote:
Originally Posted by godless_phoenix
Посмотреть сообщение
2)
a. if(!isplayerconnected(i)) continue; if(isplayerinrangeofpoint(i)) {}
b. if(!(isplayerconnected(i) && isplayerinrangeofpoint(i))) continue; else {}
If the player is not connected, it will simply return false, it wont go to isplayerinrangeofpoint because you used && operator.

That's up to you if you are going to use either:
Код:
if(conditional1)
{
    if(conditional2)
or
Код:
if(conditional1 && conditional2)
as long it's readable and comfort for you... the line break is probably just a microsecond of compilation speed difference... If you are making things more complicated just for "optimizations" or to make it faster, i bet it will be a lot of delay when you want to find where the code is located at...

Well here are some useful links for addition:
https://sampwiki.blast.hk/wiki/Control_Structures
http://www.compuphase.com/pawn/Pawn_Language_Guide.pdf

Sorry if i did some mistake, since i didn't code here for long time already, just giving my opinion.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)