04.07.2015, 15:49
Quote:
I think using arrays hardly matters, according to me its much readable than individual variables for each assignment (like your position example).
One thing i would really suggest people to limit defines (constants) to their exact usage limit. That would really save the memory and the output size. For example: You can save alot of memory by just redefining MAX_PLAYERS. pawn Код:
|
Using arrays matter a lot!!
If ****** were to be here he would have screwed you for that statement lol (because I remember him telling more organized doesn't mean more efficient)
At the MAX_PLAYERS statement, the memory you save depends more on your code. By the way no one cares about memory in 2015! But anyway it is good to keep memory usage minimum.
Quote:
Can you explain about when we should use stock or public and whats more optimized to which function?
ex: Код:
public SavePlayerData(playerid) Код:
stock SavePlayerData(playerid) Also, you didn't speak about timers and OnPlayerUpdate alot of players use OnPlayerUpdate as a timer... Also, does it matters if i'm using foreach function or for with MAX_PLAYERS in speed matters? Overall i have learned alot more from this tutorial then ****** tutorial, I dont know why. |
Hence, you must make functions public if and only if you are going to use them in CallLocalFunction/CallRemoteFunction/funcidx.
The stock keyword is optional, by prefixing a function identifier with stock only tells the compiler to not compile that function if it doesn't get called in the script.
About the OnPlayerUpdate, using OnPlayerUpdate is for timers with small interval is good instead of having to create shitlod of timers for each player. Each SetTimer/SetTimerEx you use , you make the server's overall performance less efficient and it will also take some memory. It is usually good to have one single timer (SetTimer/Ex) which checks all the players rather than having a timer for each individual player.
First of all if you are using MAX_PLAYERS, then stop using it and switch to GetPlayerPoolSize().When you have scattered playerids then foreach will be faster than using GetPlayerPoolSize Loop. But this never happens (extremely rare since SAMP gives the lowest available ID to the player who joins). GetPlayerPoolSize loop will be much faster than foreach when the player count is high, especially when the player count is nearly the max capacity.
@Cypress Gammix has answered but I would like to add some more to it. Use the subtraction loop if the order of iterations do not matter. I have never come across a situation where I had to check every player in order.
Quote:
stock
OT: Most of these optimizations only improve the execution time by milliseconds I'd bet, half of them aren't even worth the time to sit through and optimize. Put it this way: you won't need to do this in your scripts. |
Quote:
Originally Posted by sammp;
Actually, you're right. The variables are quicker than the array, sorry. But when using arrays it's much easier to contain and to sort. In scripting it's pretty much all about what gets the job done in the most readable manner. The difference in memory isnt even kbytes.
|
Array:921,921,917
Non-Array:505,532,510
By the way I never told "not to use arrays". I just said avoid them when you can.
Examples:
Код:
new params[5]; new pos[3]; new color[2];
Moreover, please justify "most of the case". I would prefer to use "few of them" make negligible improvement.
#1 I agree on this
#2 You just have no idea, it depends how many times you access the array.
Array (10 Assignments):2444,2448,2473
Non-Array (10 Assignments):972,975,963
Speed Test Code:http://pastebin.com/aMkNtaC2
#3 7x faster than using CallLocalFunction in my gamemode - hmm, how is this negligible?
#4 Anyone goes against this would have got badly screwed by ******
#5 Makes a difference when you hook SetPlayerHealth,SetPlayerPos,etc for Anti-Cheat or for some other purpose
#6 Check this
With Optimization:1102,1080,1069,1091
Without Optimization:2374,2359,2429,2364
Test Code:http://pastebin.com/SLZDGRG4
#7 I would agree on this but does make a small difference
With Optimization:134,128,129
Without Optimization:172,168,169
#8 This will improve performance to a very small extent but makes the code much more readable!
#9 You have no idea how slow floatsqrt is
#10 73.5 times faster than original code, negligible :O really?
#11 Sometimes twice as fast, sometimes thrice as fast! Negligible ye?
I have tested every optimization I have posted here whereas you made claims without checking.
If you are so least bothered about performance, then why not use dini,dcmds instead of y_ini/ZCMD?