#include<Windows.h>#include <iostream>#include<fstream>#include<vector>#include<list>#include<set>#include <map>#include <string>using namespace std;#define NUM1 10 //外层循环10次#define NUM2 100000000 //对于int、dword的1亿次i++和++i#define NUM3 100000//对与包含10万个元素容器的iter++和++iter#ifdef _DEBUG#define _FNAME "debug_"#else#define _FNAME "release_"#endiftypedef struct _ElemType1{DWORD dw;_ElemType1(DWORD _dw=0):dw(_dw){}bool operator<(_ElemType1 const &t1) const{return this->dw<t1.dw;}}ElemType1;typedef struct _ElemType2{string str;_ElemType2(string _str=""):str(_str){}bool operator<(_ElemType2 const &t1) const{return this->str<t1.str;}}ElemType2;void test1_int_i(ofstream &of);void test1_dword_i(ofstream &of);void test2_vec_type1(ofstream &of);void test2_vec_type2(ofstream &of);void test3_list_type1(ofstream &of);void test3_list_type2(ofstream &of);void test4_set_type1(ofstream &of);void test4_set_type2(ofstream &of);void test5_map_type1(ofstream &of);void test5_map_type2(ofstream &of);void test1_int_i(ofstream &of){volatile int i=0,j=0;DWORD dw1,dw2,total=0;cout<<"int类型:"<<endl;of<<"int类型:"<<endl;cout<<"i++测试:"<<endl;of<<"i++测试:"<<endl;for(;j<NUM1;++j){dw1 = ::GetTickCount();while (i<NUM2){i++;}dw2 = ::GetTickCount();i=0;cout<<j<<" : "<<dw2-dw1<<endl;of<<j<<" : "<<dw2-dw1<<endl;total+=dw2-dw1;}cout<<"总消耗:"<<total<<endl;of<<"总消耗:"<<total<<endl;cout<<"平均消耗:"<<float(total)/NUM1<<endl;of<<"平均消耗:"<<float(total)/NUM1<<endl;cout<<endl;of<<endl;i = j = 0;total = 0;cout<<"++i测试:"<<endl;of<<"++i测试:"<<endl;for(;j<NUM1;++j){dw1 = ::GetTickCount();while (i<NUM2){++i;}dw2 = ::GetTickCount();i=0;cout<<j<<" : "<<dw2-dw1<<endl;of<<j<<" : "<<dw2-dw1<<endl;total+=dw2-dw1;}cout<<"总消耗:"<<total<<endl;of<<"总消耗:"<<total<<endl;cout<<"平均消耗:"<<float(total)/NUM1<<endl;of<<"平均消耗:"<<float(total)/NUM1<<endl;cout<<endl;of<<endl;}void test1_dword_i(ofstream &of){volatile DWORD i=0,j=0;DWORD dw1,dw2,total=0;cout<<"DWORD类型:"<<endl;of<<"DWORD类型:"<<endl;cout<<"i++测试:"<<endl;of<<"i++测试:"<<endl;for(;j<NUM1;++j){dw1 = ::GetTickCount();while (i<NUM2){i++;}dw2 = ::GetTickCount();i=0;cout<<j<<" : "<<dw2-dw1<<endl;of<<j<<" : "<<dw2-dw1<<endl;total+=dw2-dw1;}cout<<"总消耗:"<<total<<endl;of<<"总消耗:"<<total<<endl;cout<<"平均消耗:"<<float(total)/NUM1<<endl;of<<"平均消耗:"<<float(total)/NUM1<<endl;cout<<endl;of<<endl;i = j = 0;total = 0;cout<<"++i测试:"<<endl;of<<"++i测试:"<<endl;for(;j<NUM1;++j){dw1 = ::GetTickCount();while (i<NUM2){++i;}dw2 = ::GetTickCount();i=0;cout<<j<<" : "<<dw2-dw1<<endl;of<<j<<" : "<<dw2-dw1<<endl;total+=dw2-dw1;}cout<<"总消耗:"<<total<<endl;of<<"总消耗:"<<total<<endl;cout<<"平均消耗:"<<float(total)/NUM1<<endl;of<<"平均消耗:"<<float(total)/NUM1<<endl;cout<<endl;of<<endl;}DWORD g_dwFlag=0;void test2_vec_type1(ofstream &of){ElemType1 t1;vector<ElemType1> vec1(NUM3,t1);DWORD dw1,dw2,total=0;cout<<"vector,使用type1:"<<endl;of<<"vector,使用type1:"<<endl;cout<<"iter++测试:"<<endl;of<<"iter++测试:"<<endl;int i = 0,j=0;vector<ElemType1>::iterator iter;vector<ElemType1>::const_iterator citer;for(;i<NUM1;++i){iter = vec1.begin();dw1 = ::GetTickCount();while (iter!=vec1.end()){#ifdef NDEBUGg_dwFlag+=i;#endifiter++;}dw2 = ::GetTickCount();cout<<i<<" : "<<dw2-dw1<<endl;of<<i<<" : "<<dw2-dw1<<endl;total+=dw2-dw1;}cout<<"总消耗:"<<total<<endl;of<<"总消耗:"<<total<<endl;cout<<"平均消耗:"<<float(total)/NUM1<<endl;of<<"平均消耗:"<<float(total)/NUM1<<endl;cout<<endl;of<<endl;i=0;total=0;cout<<"++iter测试:"<<endl;of<<"++iter测试:"<<endl;for(;i<NUM1;++i){dw1 = ::GetTickCount();iter = vec1.begin();while (iter!=vec1.end()){#ifdef NDEBUGg_dwFlag+=i;#endif++iter;}dw2 = ::GetTickCount();cout<<i<<" : "<<dw2-dw1<<endl;of<<i<<" : "<<dw2-dw1<<endl;total+=dw2-dw1;}cout<<"总消耗:"<<total<<endl;of<<"总消耗:"<<total<<endl;cout<<"平均消耗:"<<float(total)/NUM1<<endl;of<<"平均消耗:"<<float(total)/NUM1<<endl;cout<<endl;of<<endl;i=0;total=0;cout<<"citer++测试:"<<endl;of<<"citer++测试:"<<endl;for(;i<NUM1;++i){dw1 = ::GetTickCount();citer = vec1.begin();while (citer!=vec1.end()){#ifdef NDEBUGg_dwFlag+=i;#endifciter++;}dw2 = ::GetTickCount();cout<<i<<" : "<<dw2-dw1<<endl;of<<i<<" : "<<dw2-dw1<<endl;total+=dw2-dw1;}cout<<"总消耗:"<<total<<endl;of<<"总消耗:"<<total<<endl;cout<<"平均消耗:"<<float(total)/NUM1<<endl;of<<"平均消耗:"<<float(total)/NUM1<<endl;cout<<endl;of<<endl;i=0;total=0;cout<<"++citer测试:"<<endl;of<<"++citer测试:"<<endl;for(;i<NUM1;++i){dw1 = ::GetTickCount();citer = vec1.begin();while (citer!=vec1.end()){#ifdef NDEBUGg_dwFlag+=i;#endif++citer;}dw2 = ::GetTickCount();cout<<i<<" : "<<dw2-dw1<<endl;of<<i<<" : "<<dw2-dw1<<endl;total+=dw2-dw1;}cout<<"总消耗:"<<total<<endl;of<<"总消耗:"<<total<<endl;cout<<"平均消耗:"<<float(total)/NUM1<<endl;of<<"平均消耗:"<<float(total)/NUM1<<endl;cout<<endl;of<<endl;}void test2_vec_type2(ofstream &of){ElemType2 t2;vector<ElemType2> vec1(NUM3,t2);DWORD dw1,dw2,total=0;cout<<"vector,使用type2:"<<endl;of<<"vector,使用type2:"<<endl;cout<<"iter++测试:"<<endl;of<<"iter++测试:"<<endl;int i = 0,j=0;vector<ElemType2>::iterator iter;vector<ElemType2>::const_iterator citer;for(;i<NUM1;++i){dw1 = ::GetTickCount();iter = vec1.begin();while (iter!=vec1.end()){#ifdef NDEBUGg_dwFlag+=i;#endifiter++;}dw2 = ::GetTickCount();cout<<i<<" : "<<dw2-dw1<<endl;of<<i<<" : "<<dw2-dw1<<endl;total+=dw2-dw1;}cout<<"总消耗:"<<total<<endl;of<<"总消耗:"<<total<<endl;cout<<"平均消耗:"<<float(total)/NUM1<<endl;of<<"平均消耗:"<<float(total)/NUM1<<endl;cout<<endl;of<<endl;i=0;total=0;cout<<"++iter测试:"<<endl;of<<"++iter测试:"<<endl;for(;i<NUM1;++i){dw1 = ::GetTickCount();iter = vec1.begin();while (iter!=vec1.end()){#ifdef NDEBUGg_dwFlag+=i;#endif++iter;}dw2 = ::GetTickCount();cout<<i<<" : "<<dw2-dw1<<endl;of<<i<<" : "<<dw2-dw1<<endl;total+=dw2-dw1;}cout<<"总消耗:"<<total<<endl;of<<"总消耗:"<<total<<endl;cout<<"平均消耗:"<<float(total)/NUM1<<endl;of<<"平均消耗:"<<float(total)/NUM1<<endl;cout<<endl;of<<endl;i=0;total=0;cout<<"citer++测试:"<<endl;of<<"citer++测试:"<<endl;for(;i<NUM1;++i){dw1 = ::GetTickCount();citer = vec1.begin();while (citer!=vec1.end()){#ifdef NDEBUGg_dwFlag+=i;#endifciter++;}dw2 = ::GetTickCount();cout<<i<<" : "<<dw2-dw1<<endl;of<<i<<" : "<<dw2-dw1<<endl;total+=dw2-dw1;}cout<<"总消耗:"<<total<<endl;of<<"总消耗:"<<total<<endl;cout<<"平均消耗:"<<float(total)/NUM1<<endl;of<<"平均消耗:"<<float(total)/NUM1<<endl;cout<<endl;of<<endl;i=0;total=0;cout<<"++citer测试:"<<endl;of<<"++citer测试:"<<endl;for(;i<NUM1;++i){dw1 = ::GetTickCount();citer = vec1.begin();while (citer!=vec1.end()){#ifdef NDEBUGg_dwFlag+=i;#endif++citer;}dw2 = ::GetTickCount();cout<<i<<" : "<<dw2-dw1<<endl;of<<i<<" : "<<dw2-dw1<<endl;total+=dw2-dw1;}cout<<"总消耗:"<<total<<endl;of<<"总消耗:"<<total<<endl;cout<<"平均消耗:"<<float(total)/NUM1<<endl;of<<"平均消耗:"<<float(total)/NUM1<<endl;cout<<endl;of<<endl;}void test3_list_type1(ofstream &of){ElemType1 t1;list<ElemType1> ls(NUM3,t1);DWORD dw1,dw2,total=0;cout<<"list,使用type1:"<<endl;of<<"list,使用type1:"<<endl;cout<<"iter++测试:"<<endl;of<<"iter++测试:"<<endl;int i = 0,j=0;list<ElemType1>::iterator iter;list<ElemType1>::const_iterator citer;for(;i<NUM1;++i){dw1 = ::GetTickCount();iter = ls.begin();while (iter!=ls.end()){#ifdef NDEBUGg_dwFlag+=i;#endifiter++;}dw2 = ::GetTickCount();cout<<i<<" : "<<dw2-dw1<<endl;of<<i<<" : "<<dw2-dw1<<endl;total+=dw2-dw1;}cout<<"总消耗:"<<total<<endl;of<<"总消耗:"<<total<<endl;cout<<"平均消耗:"<<float(total)/NUM1<<endl;of<<"平均消耗:"<<float(total)/NUM1<<endl;cout<<endl;of<<endl;i=0;total=0;cout<<"++iter测试:"<<endl;of<<"++iter测试:"<<endl;for(;i<NUM1;++i){dw1 = ::GetTickCount();iter = ls.begin();while (iter!=ls.end()){#ifdef NDEBUGg_dwFlag+=i;#endif++iter;}dw2 = ::GetTickCount();cout<<i<<" : "<<dw2-dw1<<endl;of<<i<<" : "<<dw2-dw1<<endl;total+=dw2-dw1;}cout<<"总消耗:"<<total<<endl;of<<"总消耗:"<<total<<endl;cout<<"平均消耗:"<<float(total)/NUM1<<endl;of<<"平均消耗:"<<float(total)/NUM1<<endl;cout<<endl;of<<endl;i=0;total=0;cout<<"citer++测试:"<<endl;of<<"citer++测试:"<<endl;for(;i<NUM1;++i){dw1 = ::GetTickCount();citer = ls.begin();while (citer!=ls.end()){#ifdef NDEBUGg_dwFlag+=i;#endifciter++;}dw2 = ::GetTickCount();cout<<i<<" : "<<dw2-dw1<<endl;of<<i<<" : "<<dw2-dw1<<endl;total+=dw2-dw1;}cout<<"总消耗:"<<total<<endl;of<<"总消耗:"<<total<<endl;cout<<"平均消耗:"<<float(total)/NUM1<<endl;of<<"平均消耗:"<<float(total)/NUM1<<endl;cout<<endl;of<<endl;i=0;total=0;cout<<"++citer测试:"<<endl;of<<"++citer测试:"<<endl;for(;i<NUM1;++i){dw1 = ::GetTickCount();citer = ls.begin();while (citer!=ls.end()){#ifdef NDEBUGg_dwFlag+=i;#endif++citer;}dw2 = ::GetTickCount();cout<<i<<" : "<<dw2-dw1<<endl;of<<i<<" : "<<dw2-dw1<<endl;total+=dw2-dw1;}cout<<"总消耗:"<<total<<endl;of<<"总消耗:"<<total<<endl;cout<<"平均消耗:"<<float(total)/NUM1<<endl;of<<"平均消耗:"<<float(total)/NUM1<<endl;cout<<endl;of<<endl;}void test3_list_type2(ofstream &of){ElemType2 t2;list<ElemType2> ls(NUM3,t2);DWORD dw1,dw2,total=0;cout<<"list,使用type2:"<<endl;of<<"list,使用type2:"<<endl;cout<<"iter++测试:"<<endl;of<<"iter++测试:"<<endl;int i = 0,j=0;list<ElemType2>::iterator iter;list<ElemType2>::const_iterator citer;for(;i<NUM1;++i){dw1 = ::GetTickCount();iter = ls.begin();while (iter!=ls.end()){#ifdef NDEBUGg_dwFlag+=i;#endifiter++;}dw2 = ::GetTickCount();cout<<i<<" : "<<dw2-dw1<<endl;of<<i<<" : "<<dw2-dw1<<endl;total+=dw2-dw1;}cout<<"总消耗:"<<total<<endl;of<<"总消耗:"<<total<<endl;cout<<"平均消耗:"<<float(total)/NUM1<<endl;of<<"平均消耗:"<<float(total)/NUM1<<endl;cout<<endl;of<<endl;i=0;total=0;cout<<"++iter测试:"<<endl;of<<"++iter测试:"<<endl;for(;i<NUM1;++i){dw1 = ::GetTickCount();iter = ls.begin();while (iter!=ls.end()){#ifdef NDEBUGg_dwFlag+=i;#endif++iter;}dw2 = ::GetTickCount();cout<<i<<" : "<<dw2-dw1<<endl;of<<i<<" : "<<dw2-dw1<<endl;total+=dw2-dw1;}cout<<"总消耗:"<<total<<endl;of<<"总消耗:"<<total<<endl;cout<<"平均消耗:"<<float(total)/NUM1<<endl;of<<"平均消耗:"<<float(total)/NUM1<<endl;cout<<endl;of<<endl;i=0;total=0;cout<<"citer++测试:"<<endl;of<<"citer++测试:"<<endl;for(;i<NUM1;++i){dw1 = ::GetTickCount();citer = ls.begin();while (citer!=ls.end()){#ifdef NDEBUGg_dwFlag+=i;#endifciter++;}dw2 = ::GetTickCount();cout<<i<<" : "<<dw2-dw1<<endl;of<<i<<" : "<<dw2-dw1<<endl;total+=dw2-dw1;}cout<<"总消耗:"<<total<<endl;of<<"总消耗:"<<total<<endl;cout<<"平均消耗:"<<float(total)/NUM1<<endl;of<<"平均消耗:"<<float(total)/NUM1<<endl;cout<<endl;of<<endl;i=0;total=0;cout<<"++citer测试:"<<endl;of<<"++citer测试:"<<endl;for(;i<NUM1;++i){dw1 = ::GetTickCount();citer = ls.begin();while (citer!=ls.end()){#ifdef NDEBUGg_dwFlag+=i;#endif++citer;}dw2 = ::GetTickCount();cout<<i<<" : "<<dw2-dw1<<endl;of<<i<<" : "<<dw2-dw1<<endl;total+=dw2-dw1;}cout<<"总消耗:"<<total<<endl;of<<"总消耗:"<<total<<endl;cout<<"平均消耗:"<<float(total)/NUM1<<endl;of<<"平均消耗:"<<float(total)/NUM1<<endl;cout<<endl;of<<endl;}void test4_set_type1(ofstream &of){set<ElemType1> ls;for (int n=0;n<NUM3;++n){ls.insert(_ElemType1(n));}DWORD dw1,dw2,total=0;cout<<"set,使用type1:"<<endl;of<<"set,使用type1:"<<endl;cout<<"iter++测试:"<<endl;of<<"iter++测试:"<<endl;int i = 0,j=0;set<ElemType1>::iterator iter;set<ElemType1>::const_iterator citer;for(;i<NUM1;++i){iter = ls.begin();dw1 = ::GetTickCount();while (iter!=ls.end()){iter++;}dw2 = ::GetTickCount();cout<<i<<" : "<<dw2-dw1<<endl;of<<i<<" : "<<dw2-dw1<<endl;total+=dw2-dw1;}cout<<"总消耗:"<<total<<endl;of<<"总消耗:"<<total<<endl;cout<<"平均消耗:"<<float(total)/NUM1<<endl;of<<"平均消耗:"<<float(total)/NUM1<<endl;cout<<endl;of<<endl;i=0;total=0;cout<<"++iter测试:"<<endl;of<<"++iter测试:"<<endl;for(;i<NUM1;++i){iter = ls.begin();dw1 = ::GetTickCount();while (iter!=ls.end()){++iter;}dw2 = ::GetTickCount();cout<<i<<" : "<<dw2-dw1<<endl;of<<i<<" : "<<dw2-dw1<<endl;total+=dw2-dw1;}cout<<"总消耗:"<<total<<endl;of<<"总消耗:"<<total<<endl;cout<<"平均消耗:"<<float(total)/NUM1<<endl;of<<"平均消耗:"<<float(total)/NUM1<<endl;cout<<endl;of<<endl;i=0;total=0;cout<<"citer++测试:"<<endl;of<<"citer++测试:"<<endl;for(;i<NUM1;++i){citer = ls.begin();dw1 = ::GetTickCount();while (citer!=ls.end()){citer++;}dw2 = ::GetTickCount();cout<<i<<" : "<<dw2-dw1<<endl;of<<i<<" : "<<dw2-dw1<<endl;total+=dw2-dw1;}cout<<"总消耗:"<<total<<endl;of<<"总消耗:"<<total<<endl;cout<<"平均消耗:"<<float(total)/NUM1<<endl;of<<"平均消耗:"<<float(total)/NUM1<<endl;cout<<endl;of<<endl;i=0;total=0;cout<<"++citer测试:"<<endl;of<<"++citer测试:"<<endl;for(;i<NUM1;++i){citer = ls.begin();dw1 = ::GetTickCount();while (citer!=ls.end()){++citer;}dw2 = ::GetTickCount();cout<<i<<" : "<<dw2-dw1<<endl;of<<i<<" : "<<dw2-dw1<<endl;total+=dw2-dw1;}cout<<"总消耗:"<<total<<endl;of<<"总消耗:"<<total<<endl;cout<<"平均消耗:"<<float(total)/NUM1<<endl;of<<"平均消耗:"<<float(total)/NUM1<<endl;cout<<endl;of<<endl;}void test4_set_type2(ofstream &of){set<ElemType2> ls;char sz[255];for (int n=0;n<NUM3;++n){itoa(n,sz,10);ls.insert(ElemType2(sz));}DWORD dw1,dw2,total=0;cout<<"set,使用type2:"<<endl;of<<"set,使用type2:"<<endl;cout<<"iter++测试:"<<endl;of<<"iter++测试:"<<endl;int i = 0,j=0;set<ElemType2>::iterator iter;set<ElemType2>::const_iterator citer;for(;i<NUM1;++i){iter = ls.begin();dw1 = ::GetTickCount();while (iter!=ls.end()){iter++;}dw2 = ::GetTickCount();cout<<i<<" : "<<dw2-dw1<<endl;of<<i<<" : "<<dw2-dw1<<endl;total+=dw2-dw1;}cout<<"总消耗:"<<total<<endl;of<<"总消耗:"<<total<<endl;cout<<"平均消耗:"<<float(total)/NUM1<<endl;of<<"平均消耗:"<<float(total)/NUM1<<endl;cout<<endl;of<<endl;i=0;total=0;cout<<"++iter测试:"<<endl;of<<"++iter测试:"<<endl;for(;i<NUM1;++i){iter = ls.begin();dw1 = ::GetTickCount();while (iter!=ls.end()){++iter;}dw2 = ::GetTickCount();cout<<i<<" : "<<dw2-dw1<<endl;of<<i<<" : "<<dw2-dw1<<endl;total+=dw2-dw1;}cout<<"总消耗:"<<total<<endl;of<<"总消耗:"<<total<<endl;cout<<"平均消耗:"<<float(total)/NUM1<<endl;of<<"平均消耗:"<<float(total)/NUM1<<endl;cout<<endl;of<<endl;i=0;total=0;cout<<"citer++测试:"<<endl;of<<"citer++测试:"<<endl;for(;i<NUM1;++i){citer = ls.begin();dw1 = ::GetTickCount();while (citer!=ls.end()){citer++;}dw2 = ::GetTickCount();cout<<i<<" : "<<dw2-dw1<<endl;of<<i<<" : "<<dw2-dw1<<endl;total+=dw2-dw1;}cout<<"总消耗:"<<total<<endl;of<<"总消耗:"<<total<<endl;cout<<"平均消耗:"<<float(total)/NUM1<<endl;of<<"平均消耗:"<<float(total)/NUM1<<endl;cout<<endl;of<<endl;i=0;total=0;cout<<"++citer测试:"<<endl;of<<"++citer测试:"<<endl;for(;i<NUM1;++i){citer = ls.begin();dw1 = ::GetTickCount();while (citer!=ls.end()){++citer;}dw2 = ::GetTickCount();cout<<i<<" : "<<dw2-dw1<<endl;of<<i<<" : "<<dw2-dw1<<endl;total+=dw2-dw1;}cout<<"总消耗:"<<total<<endl;of<<"总消耗:"<<total<<endl;cout<<"平均消耗:"<<float(total)/NUM1<<endl;of<<"平均消耗:"<<float(total)/NUM1<<endl;cout<<endl;of<<endl;}void test5_map_type1(ofstream &of){map<int,ElemType1> ls;for (int n=0;n<NUM3;++n){ls.insert(pair<int,ElemType1>(n,ElemType1(n)));}DWORD dw1,dw2,total=0;cout<<"map,使用type1:"<<endl;of<<"map,使用type1:"<<endl;cout<<"iter++测试:"<<endl;of<<"iter++测试:"<<endl;int i = 0,j=0;map<int,ElemType1>::iterator iter;map<int,ElemType1>::const_iterator citer;for(;i<NUM1;++i){iter = ls.begin();dw1 = ::GetTickCount();while (iter!=ls.end()){iter++;}dw2 = ::GetTickCount();cout<<i<<" : "<<dw2-dw1<<endl;of<<i<<" : "<<dw2-dw1<<endl;total+=dw2-dw1;}cout<<"总消耗:"<<total<<endl;of<<"总消耗:"<<total<<endl;cout<<"平均消耗:"<<float(total)/NUM1<<endl;of<<"平均消耗:"<<float(total)/NUM1<<endl;cout<<endl;of<<endl;i=0;total=0;cout<<"++iter测试:"<<endl;of<<"++iter测试:"<<endl;for(;i<NUM1;++i){iter = ls.begin();dw1 = ::GetTickCount();while (iter!=ls.end()){++iter;}dw2 = ::GetTickCount();cout<<i<<" : "<<dw2-dw1<<endl;of<<i<<" : "<<dw2-dw1<<endl;total+=dw2-dw1;}cout<<"总消耗:"<<total<<endl;of<<"总消耗:"<<total<<endl;cout<<"平均消耗:"<<float(total)/NUM1<<endl;of<<"平均消耗:"<<float(total)/NUM1<<endl;cout<<endl;of<<endl;i=0;total=0;cout<<"citer++测试:"<<endl;of<<"citer++测试:"<<endl;for(;i<NUM1;++i){citer = ls.begin();dw1 = ::GetTickCount();while (citer!=ls.end()){citer++;}dw2 = ::GetTickCount();cout<<i<<" : "<<dw2-dw1<<endl;of<<i<<" : "<<dw2-dw1<<endl;total+=dw2-dw1;}cout<<"总消耗:"<<total<<endl;of<<"总消耗:"<<total<<endl;cout<<"平均消耗:"<<float(total)/NUM1<<endl;of<<"平均消耗:"<<float(total)/NUM1<<endl;cout<<endl;of<<endl;i=0;total=0;cout<<"++citer测试:"<<endl;of<<"++citer测试:"<<endl;for(;i<NUM1;++i){citer = ls.begin();dw1 = ::GetTickCount();while (citer!=ls.end()){++citer;}dw2 = ::GetTickCount();cout<<i<<" : "<<dw2-dw1<<endl;of<<i<<" : "<<dw2-dw1<<endl;total+=dw2-dw1;}cout<<"总消耗:"<<total<<endl;of<<"总消耗:"<<total<<endl;cout<<"平均消耗:"<<float(total)/NUM1<<endl;of<<"平均消耗:"<<float(total)/NUM1<<endl;cout<<endl;of<<endl;}void test5_map_type2(ofstream &of){map<int,ElemType2> ls;char sz[255];for (int n=0;n<NUM3;++n){itoa(n,sz,10);ls.insert(pair<int,ElemType2>(n,ElemType2(sz)));}DWORD dw1,dw2,total=0;cout<<"map,使用type2:"<<endl;of<<"map,使用type2:"<<endl;cout<<"iter++测试:"<<endl;of<<"iter++测试:"<<endl;int i = 0,j=0;map<int,ElemType2>::iterator iter;map<int,ElemType2>::const_iterator citer;for(;i<NUM1;++i){iter = ls.begin();dw1 = ::GetTickCount();while (iter!=ls.end()){iter++;}dw2 = ::GetTickCount();cout<<i<<" : "<<dw2-dw1<<endl;of<<i<<" : "<<dw2-dw1<<endl;total+=dw2-dw1;}cout<<"总消耗:"<<total<<endl;of<<"总消耗:"<<total<<endl;cout<<"平均消耗:"<<float(total)/NUM1<<endl;of<<"平均消耗:"<<float(total)/NUM1<<endl;cout<<endl;of<<endl;i=0;total=0;cout<<"++iter测试:"<<endl;of<<"++iter测试:"<<endl;for(;i<NUM1;++i){iter = ls.begin();dw1 = ::GetTickCount();while (iter!=ls.end()){++iter;}dw2 = ::GetTickCount();cout<<i<<" : "<<dw2-dw1<<endl;of<<i<<" : "<<dw2-dw1<<endl;total+=dw2-dw1;}cout<<"总消耗:"<<total<<endl;of<<"总消耗:"<<total<<endl;cout<<"平均消耗:"<<float(total)/NUM1<<endl;of<<"平均消耗:"<<float(total)/NUM1<<endl;cout<<endl;of<<endl;i=0;total=0;cout<<"citer++测试:"<<endl;of<<"citer++测试:"<<endl;for(;i<NUM1;++i){citer = ls.begin();dw1 = ::GetTickCount();while (citer!=ls.end()){citer++;}dw2 = ::GetTickCount();cout<<i<<" : "<<dw2-dw1<<endl;of<<i<<" : "<<dw2-dw1<<endl;total+=dw2-dw1;}cout<<"总消耗:"<<total<<endl;of<<"总消耗:"<<total<<endl;cout<<"平均消耗:"<<float(total)/NUM1<<endl;of<<"平均消耗:"<<float(total)/NUM1<<endl;cout<<endl;of<<endl;i=0;total=0;cout<<"++citer测试:"<<endl;of<<"++citer测试:"<<endl;for(;i<NUM1;++i){citer = ls.begin();dw1 = ::GetTickCount();while (citer!=ls.end()){++citer;}dw2 = ::GetTickCount();cout<<i<<" : "<<dw2-dw1<<endl;of<<i<<" : "<<dw2-dw1<<endl;total+=dw2-dw1;}cout<<"总消耗:"<<total<<endl;of<<"总消耗:"<<total<<endl;cout<<"平均消耗:"<<float(total)/NUM1<<endl;of<<"平均消耗:"<<float(total)/NUM1<<endl;cout<<endl;of<<endl;}#define LOGFILE_PATH_A L"qin_nkl_23529303.etl"int main(){string strFileName = _FNAME;string strTime = __TIME__;for(int k=0;k<strTime.length();++k)if(strTime[k]==':')strTime[k]='-';strFileName+=strTime;strFileName+="_test1.txt";//文件测试用char sz[MAX_PATH];sprintf(sz,"F:\\parse_%s_%d.txt",LOGFILE_PATH_A,GetTickCount());cout<<sz<<endl;sprintf(sz,"F:\\parse_%S_%d.txt",LOGFILE_PATH_A,GetTickCount());cout<<sz<<endl;cin.get();return 0;//strFileName = sz;ofstream of(strFileName.c_str());of<<GetTickCount()<<endl;of.flush();of.close();cin.get();return 0;test1_int_i(of);test1_dword_i(of);test2_vec_type1(of);test2_vec_type2(of);test3_list_type1(of);test3_list_type2(of);test4_set_type1(of);test4_set_type2(of);test5_map_type1(of);test5_map_type2(of);cout<<"标记:"<<g_dwFlag<<endl;of.flush();of.close();cin.get();return 0;}
相关文章: