So lately I've been trying to figure out how 'heavy' some statements are. For example is it a good thing to check for every possible exception with if statements or will that slow down the programm considerably? So I bassically want to know how 'heavy' the folling statements get when used a lot. This is mostly just a question out of curiosity because today's computer are so fast that it probably doesn't matter But it will also help me choose between different ways of doing things though perfomance improvements might only be minimal.
A simple while loop how 'heavy' is the loop itself not the code inside it?
while(true){}
A for loop probably smiliar to the while loop?
for(int i = 0; true; i++){}
A do while loop probably smiliar to the above two too?
do{...}while(true)
An if statement how 'heavy' does this get?
if(true){}
A switch statement
switch(0){
case 0:
}
And is a switch statement less 'heavy' or 'heavier' than else if
statements
And the instanceof check how 'heavy' is it?
if(obj instanceof Player){}
An is null
check I heard that this one is really 'light' is that true?
if(obj == null){}
And a constructor call
new Object();
And a method call
MyClass.doSomething();
A variable assignment
int i = 10;
I tried searching on the internet but I didn't find a web page that was comparing them all to each other or something smiliar. But if some of you have a good documentation on this I would be more than happy to read it.