Multiple variables vs one variable speed performance?
#1

Hello. I have a question about best anticheat checks that are placed inside foreach loops. I need precise and correct answer for usage of variables, since I don't know is it better to use one variable created on top of timer of anticheat and then used for each player to check if they are cheating or not. So the variable's value will be changed ~300 times in loop and loop needs to be finished asap efficiently. I've seen that I've created a stock function where the new variable is being declared in that stock.

CODE:

Код:
stock Checksomething( playerid ) {
new x;
// using x here
}

public anticheat() {
    foreach ( new i : Player ) {
         Checksomething( i );

    }

}
and I've replaced it to:

Код:
public anticheat() {
    new x;
    foreach ( new i : Player ) {
          // CODE USING x VARIABLE THAT'S DECLARED IN THIS TIMER, NOT IN FUNCTION.
    }
}
Which code is more efficient and why?
Reply
#2

Oh well how do you use x?
Reply
#3

I just mentioned x as an example, although x will have it's value changed throughout the loop many times since the loop will be performed on over 200 online players.
Reply
#4

Ok then I bet my money on the stock then.
Reply
#5

There would be no difference that is noticeable. Technically, calling another function would add more execution time, but it would be so miniscule you would never notice (seriously).

Create your script, test it and profile it, THEN, if you need to improve the performance, focus on the calls with the highest execution time.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)