In "Java Performance The Definite Guide" there's an example showing problems with writing a microbenchmark. The code is something like this:
public void test(){
double l;
long then = System.currentTimeMillis();
for (int i = 0; i < n; i++) {
l = fib(50);
}
long now = System.currentTimeMillis();
System.out.println("Time: " + (now - then));
}
The book mentions that "A smart compiler will end up executing this code" :
long then = System.currentTimeMillis();
long now = System.currentTimeMillis();
System.out.println("Elapsed time: " + (now - then));
I see that "l" is a local unused variable, and it would make sense to ignore it , but I don't see how it's done or how to prove that it works like this. I tried running the code and it seems that the fib() method is executed. I also looked at the .class file and all the lines are included. How do I check that it works as mentioned above ?