Given the following code snippet, which generates a UUID.randomUUID(), I get the following performance results (in milliseconds):
public static void main(String[] args) { long tmp = System.currentTimeMillis(); UUID.randomUUID(); tmp = printDiff(tmp); UUID.randomUUID(); tmp = printDiff(tmp); UUID.randomUUID(); tmp = printDiff(tmp); UUID.randomUUID(); tmp = printDiff(tmp); } private static long printDiff(final long previousTimestamp) { long tmp = System.currentTimeMillis(); System.out.printf("%s%n", tmp - previousTimestamp); return tmp; } Results:
971 6 0 0 JDK: 1.8 OS: Windows 7
Why does only the initial call take so long? (Nearly 1 second!)