Drakath Posted December 13, 2014 Share Posted December 13, 2014 I have a script which uses about 15 getDistanceBetweenPoints3D functions. Would it be more efficient to make this function: function getDistToElement(element,Px,Py,Pz) local x,y,z = getElementPosition(element) return getDistanceBetweenPoints3D(Px,Py,Pz,x,y,z) end and use it instead of all other getDistanceBetweenPoints3D? Link to comment
Saml1er Posted December 13, 2014 Share Posted December 13, 2014 You're still calling it 15 times so this won't make a big difference. Link to comment
MTA Team 0xCiBeR Posted December 13, 2014 MTA Team Share Posted December 13, 2014 Actually, making a entire function for it would be less efficient as you are nesting a new function and calling it 15 times. It would take less time & less memory size just to call the MTA function directly. Example: Execution Data: 0.02s memory: 2496KB local var = "xD" print(var) print(var) print(var) print(var) print(var) print(var) print(var) print(var) print(var) print(var) print(var) print(var) print(var) print(var) print(var) Execution Data: 0.03s memory: 2540KB function out(value) return print(value) end local var = "xD" out(var) out(var) out(var) out(var) out(var) out(var) out(var) out(var) out(var) out(var) out(var) out(var) out(var) out(var) out(var) Link to comment
manawydan Posted December 13, 2014 Share Posted December 13, 2014 ciber how do you calculate the time of Execution? Link to comment
Drakath Posted December 13, 2014 Author Share Posted December 13, 2014 Thanks for the information. Link to comment
MTA Team 0xCiBeR Posted December 14, 2014 MTA Team Share Posted December 14, 2014 No problem. ciber how do you calculate the time of Execution? In the case that you are testing native Lua functions, i just use a Lua engine. Otherwise, you can calculate execution time approximately using getTickCount This function returns amount of time that your system has been running in milliseconds. By comparing two values of getTickCount, you can determine how much time has passed (in milliseconds) between two events. This could be used to determine how efficient your code is, or to time how long a player takes to complete a task. Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now