In Lua, it is slightly faster to put a function you call often from a global math library. For example:
local variable = math.sin
Instead of math.sin(x)
, you would now use it as variable(x)
(bad naming used for demonstration purposes).
Well, what about C#? Imagine you want to call method Class.method()
one million times. I assume it would be faster to put that method inside a variable, but how would I do that?
In my case, I am calling function Mathf.PerlinNoise
thousands of times relatively frequently and I would like to put it inside a variable.
How do I do that and should I even bother? How much can this affect performance in extreme cases (tens of millions of calls for example)?