If you do
new Date()
he calls
public Date() {
this(System.currentTimeMillis());
}
therefore, it calls System.currentTimeMillis () and creates an object that you immediately throw away.
If you're very lucky, an escape analysis will remove the redundant object, and performance will be pretty much the same.
However, I would not have expected Escape Analysis to come out and just call
long start = System.currentTimeMillis();
// do something
long time = System.currentTimeMillis() - start;
Notes:
- , , Date . : ) ) , . ( ), , esp .
- 1 , , , ( ). , , . - , , , .
- System.nanoTime() , . , . , System.currentTimeMillis() .
- -, , . 2 - 10 , , .