Golang map and Java HashMap Performance comparison

Source: Internet
Author: User
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");

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.