Vague title, I know. Been awhile since I've posted here. Ignore the prefix, the question concerns javascript itself.
I have a bit of code. This bit of code will occur every frame update, hence why I ask which approach is faster.
In this code I have a formula that requires getting a value from a property. Stepping through the code reveals that grabbing this property's value jumps through two other points in the code. There are two of these properties I'm grabbing, and the values are used twice each.
So here's the question. Is it faster to simply grab the property values directly both times, or grab it once to store it in a variable, and then use the variable itself those two times? Is there any real appreciable difference in speed, even if I were to drastically scale up the number of times I used said property value? Or even the number of similar properties I'm accessing each frame?
I don't INTEND to go that massive, but the project I'm working on is a plugin with a great deal of high-degree customization options for the user, so I'd like to know the more time-efficient method just in case someone decides to get.... stupidly creative. 😛
There won't be a great deal of such access in any one function, but there isn't a limit to a chain of such functions that a user could theoretically implement.
I've not really delved very far into the topic of time complexity or memory usage, and even cursory inspection on the topics usually implies a LARGE amount of a given operation being done in sequence. Given the frequency with which I'm going to be potentially running one of any number of defined functions, I figured I'd see if there was a definite advantage to one approach over another before I started really getting into writing all those functions.
I have a bit of code. This bit of code will occur every frame update, hence why I ask which approach is faster.
In this code I have a formula that requires getting a value from a property. Stepping through the code reveals that grabbing this property's value jumps through two other points in the code. There are two of these properties I'm grabbing, and the values are used twice each.
So here's the question. Is it faster to simply grab the property values directly both times, or grab it once to store it in a variable, and then use the variable itself those two times? Is there any real appreciable difference in speed, even if I were to drastically scale up the number of times I used said property value? Or even the number of similar properties I'm accessing each frame?
I don't INTEND to go that massive, but the project I'm working on is a plugin with a great deal of high-degree customization options for the user, so I'd like to know the more time-efficient method just in case someone decides to get.... stupidly creative. 😛
There won't be a great deal of such access in any one function, but there isn't a limit to a chain of such functions that a user could theoretically implement.
I've not really delved very far into the topic of time complexity or memory usage, and even cursory inspection on the topics usually implies a LARGE amount of a given operation being done in sequence. Given the frequency with which I'm going to be potentially running one of any number of defined functions, I figured I'd see if there was a definite advantage to one approach over another before I started really getting into writing all those functions.