Jump to content

Variable access speed


JeViCo

Recommended Posts

I know that variable access speed higher for local variables. Does this work on functions as well? Can i do something like this at the beginning of the script:

local tocolor = tocolor
local dxGetTextWidth = dxGetTextWidth
local dxGetFontHeight = dxGetFontHeight
local dxDrawText = dxDrawText
local dxDrawImage = dxDrawImage
local getElementPosition = getElementPosition
local getElementRotation = getElementRotation
local getPedCameraRotation = getPedCameraRotation
local getDistanceBetweenPoints2D = getDistanceBetweenPoints2D
local dxGetMaterialSize = dxGetMaterialSize
local getElementData = getElementData

 

Link to comment
  • Moderators
2 hours ago, JeViCo said:

Does this work on functions as well?

In general it does matter. A function name is a variable after all.

But for MTA(C++) functions you have to make an exception. For some unknown reason they are just as fast as localized functions. (I tested that a while back.)

For self created functions, yes localized is faster accessible.

 

Feel free to re-test it.

Loop i= 1000 + getTickCount

 

 

Note, this matters: (but not because it is localized, but because it pre-indexed)

local tableRemove = table.remove

 

Edited by IIYAMA
  • Thanks 1
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...