C + + several code optimization records __c++

Source: Internet
Author: User
The following is based on debug debug mode,
Map<int, string> MSS;
 clock_t C1, C2;
 C1 = Clock ();
 for (int i=0; i<500000; i++)
 {
     unsigned int lun = 123324; 
     Char num[] = "012345678912";
     vector<char> VV;

     "1" ostringstream efficiency is lower than _itoa_s

     //ostringstream Lstrstream;
     lstrstream<<lun;                            Time consuming 6.875 seconds

     //char cc[12];
     _itoa_s (LUN, CC, a);                   Time consuming 0.063 seconds

     //"2" map[index]= value efficiency is lower than map.insert

     //mss[i] = "ABDFADAF";                        Time consuming 9.172 seconds
     //mss.insert (Make_pair (i, "ABDFADAF"));       Time consuming 7.454 seconds

     //"3" vector single push_back efficiency lower than Vector.insert
     //for (int n=0; n<12; n++)                    //time consuming 30.344 seconds
     / /{
     //    Vv.push_back (Num[n]);
     }
     //vv.insert (Vv.end (), &num[0], &num[0]+12);    Time consuming 3.079 seconds
 }
 c2 = Clock ();
 Double d = (double) (C2-C1)/clocks_per_sec;


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.