Is there any differences in performance between declaring variables at the beginning of code and declaring them when I need them (outside of readability arguments)?
Suppose I have the following two options:
Option1:
public void methodA ()
{
int amount;
long id;
String name;
//do something
}
Option2:
public void methodB ()
{
int amount;
//do something
long id;
//do something
String name;
//do something
}
In my opinion, option 2 is more aesthetic and readable and thus is my preference.
Q: But I am just wondering if there exist any differences in performance related to the location of those declarations.
Edit: Thanks to the input of maaartinus, I found that my benchmark examples were wrong (now deleted) and I am looking further into how to write/use benchmark code.