'Why HashMap put so much faster after jdk8?
Why does this class, built with Java 8, run ~5x faster on Java 11 than Java 8?
import java.time.Duration;
import java.time.LocalDateTime;
import java.util.HashMap;
public class JMapSpeed {
public static void main(String[] args) {
HashMap<Integer, Integer> map = new HashMap<>(10_000_000);
LocalDateTime start=LocalDateTime.now();
for (Integer n=0; n< 10_000_000; n++) {
map.put(n,n);
}
LocalDateTime stop= LocalDateTime.now();
System.out.println("Duration: " + Duration.between(start, stop).toMillis());
System.out.println("Iterations: " + map.size());
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|