PtokaX forum

Development Section => Your Developing Problems => Topic started by: bastya_elvtars on 08 September, 2004, 15:48:12

Title: Resources
Post by: bastya_elvtars on 08 September, 2004, 15:48:12
I would like to get some exact information on minimizing the resource (CPU & RAM) usage of a script.

offtopic: sorry for so many questions, but i had a whole summer to collect them :D :D :D
Title:
Post by: Herodes on 08 September, 2004, 17:48:03
One think to watch for is the loops

for i,v in table do
-- toDo() :)
end

while 1 do
--- toDo()
end

repeat
--- toDo()
until (condition_met)
these are all cpu consuming ... but they are usually used in quick parts ...

Another thing that should be avoided is the global variables ...
You can see the globals of your script by using the following bit ...
for i , v in globals() do
   if type(v) == "number" or type(v) == "string" then
   SendToAll(i.." with a value of "..v.." and it is a "..type(v))
   end
end
Note: this snippet can be terribly better ;)

and from the outcome of that by observing how each variable is used you can start eliminating one by one if possible ...
Title:
Post by: bastya_elvtars on 08 September, 2004, 18:44:30
I have made almost all variables local, and im using the least loops. Also i tried 2 avoid pattern matching wherever it was possible. Can something more be done?