Check or direct function executing?
#1

This may sound a bit minor but i wanna ask:
What would be better to use, a check or the function should get executed right away?

pawn Код:
public OnPlayerDeath(playerid, killerid, reason)
{
    if(GetPlayerWantedLevel(playerid) > 0)
    {
        SetPlayerWantedLevel(playerid, 0);
    }
    return 1;
}
or directly

pawn Код:
public OnPlayerDeath(playerid, killerid, reason)
{
    SetPlayerWantedLevel(playerid, 0);
    return 1;
}
Thanks, regards.
Reply
#2

I would prefer the second methode

but you could test what methode faster is
Reply
#3

Ill do that, thanks.
Reply
#4

Well obviously the second one is faster in general, because the worst case scenario in the first example is that you're calling 2 functions, the second example will always result in one function being called.

However! There is another factor, what if the checking function executes faster than the setting function? Then in some cases it may be better to do the check, but generally in most cases, it is not. At least not for a single function.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)