Jump to content

Call function or repeat


Drakath

Recommended Posts

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
  • MTA Team

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
  • MTA Team

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...