This is a creation in Article, where the information may have evolved or changed.
Performance comparison
Insert 10 million records to compare memory usage size and insertion time.
Test machine configuration
Intel (R) Core (TM) i3-4000m CPU @2.40ghz 2.40GHz
12.0GB Memory
Front-facing conditions
Go, avoid the memory copy when expanding capacity, the size of the initialization volume is 13333333. Make (map[int]int,13333333)
Java, avoid memory copy when expanding capacity, the size of initialization volume is 13333333. New HashMap (13333333);
Avoid oom, set JVM parameters-xms2048m-xmx2048m
Use the size of the memory
Go 300M
Java 800M
Time-consuming (nanosecond)
Go put map,duration:2655163300 NS
Java put map,duration:1543360398 NS
Code
Golang
T1:=time. Now ();
M1:=make (map[int]int,13333333)
For i:=0;i<10000000;i++{
M1[i]=i
}
T2:=time. Now ();
Fmt. Printf ("Put map,duration::%d ns\n", T2. Sub (t1))
Java
System.GC ();
Long T1 = System.nanotime ();
Map map = new hashmap<> (13333333);
for (int i=0;i<10000000;i++) {
Map.put (i, I);
}
Long t2 = System.nanotime ();
System.out.println ("Put map,duration:" + (T2-T1) + "ns");