C++几处代码优化记录

 //以下基于Debug调试模式,
 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 效率低于_itoa_s

     //ostringstream lstrStream;
     //lstrStream<<lun;                            //耗时6.875秒

     //char cc[12];
     //_itoa_s(lun, cc, 12, 10);                   //耗时0.063秒

     //【2】map[索引]=值 效率低于 map.insert

     //mss[i] = "abdfadaf";                        //耗时9.172秒
     //mss.insert(make_pair(i, "abdfadaf"));       //耗时7.454秒

     //【3】vector单个push_back 效率低于 vector.insert
     //for (int n=0; n<12; n++)                    //耗时30.344秒
     //{
     //    vv.push_back(num[n]);
     //}
     //vv.insert(vv.end(), &num[0], &num[0]+12);    //耗时3.079秒
 }
 c2 = clock();
 double d = (double)(c2-c1)/CLOCKS_PER_SEC;


你可能感兴趣的:(C++几处代码优化记录)