Let’s say i’m calling sequentially a calculation_method() nearly 80000 times per seconds.
While coding this, all my floats variables that are used in this calculation_method(), i’m declaring them in the class, in order to not surcharge the garbage collector. Am i right ?
Or should i declare my floats variables inside my calculation_method() ?
In Java, can sometimes local variable run a bit faster than global variables or never ?
Is there something to worry about or not ?
Yeah, even though you are saving a declaration by declaring an instance or static variable from what I’ve read it can take 2-3 times as long to access and modify that variable versus using a local variable. One thing you can look out for optimizing is avoiding declaring local variables within loops (probably obvious if you are asking this question).