Dejo aquí un codekata en Java de copia y pega para medir tiempos.
import java.time.Clock;
import java.util.Date;
class Main {
public static void main(String[] args) throws Exception {
System.out.println();
System.out.println("Clock.systemUTC().millis() = " + Clock.systemUTC().millis());
System.out.println("System.currentTimeMillis() = " + System.currentTimeMillis());
System.out.println(" System.nanoTime() = " + System.nanoTime());
System.out.println(" (new Date()) = " + (new Date()));
System.out.println(" (new Date()).getTime()) = " + (new Date()).getTime());
System.out.println();
Thread.sleep(3000);
System.out.println();
System.out.println("Clock.systemUTC().millis() = " + Clock.systemUTC().millis());
System.out.println("System.currentTimeMillis() = " + System.currentTimeMillis());
System.out.println(" System.nanoTime() = " + System.nanoTime());
System.out.println(" (new Date()) = " + (new Date()));
System.out.println(" (new Date()).getTime()) = " + (new Date()).getTime());
System.out.println();
/*
* Se recomienda usar nanoTime(), aunque es cíclico,
* porque es más rápido de obtener que
* currentTimeMillis().
*/
Long startTime = System.nanoTime();
Thread.sleep(1000);
Long endTime = System.nanoTime();
System.out.println("Nanosegundos consumidos = " + (endTime - startTime));
}
}
Si todo va bien, se tiene que ver por pantalla algo tal que así: