Performance comparison of map implementations for C + + performance

Source: Internet
Author: User

Http://www.cnblogs.com/zhjh256/p/6346501.html tells the basic map operation, when testing, found that the performance of the map is very low, compared with Java is nearly 200 times times. The logic of the test is as follows:

    //Map Definitionmap<int, firstcppcls*>mapstudent;  for(i=0;i<10000; i++) {firstcppcls clz; Clz.setappversion ("12.32.33"); Clz.setclustername ("Osm-service"); Clz.setcompanyid ("239383"); Clz.setserviceid ("sysl.1.223"); Clz.setsubsystemid (" at"); Clz.setsystemid (" +"); Mapstudent.insert (Pair<int, Firstcppcls*> (i, &clz)); }    //get time-relative counter, VC-specificBegin =GetTickCount ();  for(j=0;j< -; j + +) {         for(f=0;f<10000; f++) {            //Map LookupMapstudent.find (f); }} End=GetTickCount (); //Print Time Differencecout <<"Map Lookup time consuming:"<< (End-begin) << Endl;//about 4 seconds on average .System"Pause");

In Java the same implementation, get 100 0000 times only took 20ms. So search C + + map performance, see the two posts are as follows:

http://blog.csdn.net/a418382926/article/details/22302907

Http://blog.sina.com.cn/s/blog_5f93da790101hxxi.html

Http://www.ideawu.net/blog/archives/751.html

Subsequently, the HASH_MAP and unordered_map tests are performed, as follows:

    //hash_map Definitionhash_map<int, firstcppcls*>hash_mapstudent;  for(i=0;i<10000; i++) {firstcppcls clz; Clz.setappversion ("12.32.33"); Clz.setclustername ("Osm-service"); Clz.setcompanyid ("239383"); Clz.setserviceid ("sysl.1.223"); Clz.setsubsystemid (" at"); Clz.setsystemid (" +"); Hash_mapstudent.insert (Pair<int, Firstcppcls*> (i, &clz)); }    //get time-relative counter, VC-specificBegin =GetTickCount ();  for(j=0;j< -; j + +) {         for(f=0;f<10000; f++) {            //Map LookupHash_mapstudent.find (f); }} End=GetTickCount (); //Print Time Differencecout <<"HashMap Find time:"<< (End-begin) << Endl;//about 4 seconds on average .System"Pause"); //hash_map Definitionunordered_map<int, firstcppcls*>unordered_mapstudent;  for(i=0;i<10000; i++) {firstcppcls clz; Clz.setappversion ("12.32.33"); Clz.setclustername ("Osm-service"); Clz.setcompanyid ("239383"); Clz.setserviceid ("sysl.1.223"); Clz.setsubsystemid (" at"); Clz.setsystemid (" +"); Unordered_mapstudent.insert (Pair<int, Firstcppcls*> (i, &clz)); }    //get time-relative counter, VC-specificBegin =GetTickCount ();  for(j=0;j< -; j + +) {         for(f=0;f<10000; f++) {            //Map LookupUnordered_mapstudent.find (f); }} End=GetTickCount (); //Print Time Differencecout <<"Unorderedmap Find time:"<< (End-begin) << Endl;//about 4 seconds on average .System"Pause");

The output is as follows:

HashMap Find time: 1610 Please press any key to continue ... Unorderedmap Find time: 1797 please press any key to continue ...

Although, compared to Std::map, did raise more than 50%, but with Java, or slow mess, because the STL has not been studied, not sure what the specific cause.

Performance comparison of map implementations for C + + performance

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.