reading a MC Donalds Menu wont take that long as reading a Phone Book. it needs more time to be read cause its longer. a longer script takes more CPU time to complete than a short one - as long each command gets executed 1 single time - for programing, this is not really valid, due to algorithms (executing commands on a iterative/recursive base):
my gamemode is close to 18000 lines, but regardless of the players/npcs amount logged in, despite if theyre spamming commands/chat, and using approx. 10 timers: its not lagging (using 5-6% CPU constantly), this leaves 94% for other scripts to run. (like fireworks using another 10%, or another 60% for the pathfinding)
all those ms/percentual estimations are the most vital part of checking for server lag - if a timer (its function being ececuted) takes longer to complete than its set interval, THEN your server will "lag", not being able to perform tasks like detecting players entering pickups/checkpoints (will drive through them), commands will get processed with the mentioned delay (which will sum up!).
heres a little snippet which you should NOT try to run:
Код:
for(new IterA=0;IterA<1000;IterA++){
for(new IterB=0;IterB<1000;IterB++){
for(new IterC=0;IterC<1000;IterC++){
}
}
}
... pay attention to the loops intervals: each loop got set to 1000 times to repeat. due to the loops are nested, the required iterations are 1000*1000*1000 = 1000000000. this will cause some seconds lag if you add that into a command,
while this wont lag at all:
Код:
for(new IterA=0;IterA<1000;IterA++){
}
for(new IterB=0;IterB<1000;IterB++){
}
for(new IterC=0;IterC<1000;IterC++){
}
...3 loops with 1000 iterations each, but NOT nested, this means linear runtime - 3000 iterations needed..
compare those 2 variants' runtime, its 1000000000/3000= 333333 x faster - the script got the same lenght btw: 6 lines. the difference between scripting the first/second method, are best described as:
first = fail/lag/crash
second = success
edit: i forgot to mention 2 invaluable plugins:
JIT Compiler and
Performance profiler