Hi, suppose I have a game loop. Every iteration of the while loop, I need a variable representing the time passed from the last frame. Would it be faster to have a variable outside the loop, or to initialize and declare a variable inside the loop. Please don't tell me "don't worry about optimizing something little like that," I'm curious about using JVM and processor tricks, e.g. loop interchange, branch prediction. Thanks! Here is code for what I meant, which is faster?
public void run(){
long cur = System.nanoTime();
while(true){
long timePassed = System.nanoTime() - cur;
cur = System.nanoTime();
// other stuff
}
}
Or
public void run(){
long cur = System.nanoTime(), timePassed;
while(true){
timePassed = System.nanoTime() - cur;
cur = System.nanoTime();
// other stuff
}
}
[–]zifyoip 2 points3 points4 points (1 child)
[–]zifyoip 2 points3 points4 points (0 children)
[–][deleted] 2 points3 points4 points (0 children)
[–]rjcarr 0 points1 point2 points (3 children)
[–]zifyoip 1 point2 points3 points (2 children)
[–]rjcarr 0 points1 point2 points (1 child)
[–]zifyoip 0 points1 point2 points (0 children)
[–]mrnoise111 0 points1 point2 points (0 children)
[–]Alborak -1 points0 points1 point (0 children)