1. #include<Windows.h>
  2.  
  3. #include <iostream>
  4.  
  5. #include<fstream>
  6.  
  7. #include<vector>
  8.  
  9. #include<list>
  10.  
  11. #include<set>
  12.  
  13. #include <map>
  14.  
  15. #include <string>
  16.  
  17. using namespace std;
  18.  
  19. #define NUM1 10 //外层循环10次
  20.  
  21. #define NUM2 100000000 //对于int、dword的1亿次i++和++i
  22.  
  23. #define NUM3 100000//对与包含10万个元素容器的iter++和++iter
  24.  
  25. #ifdef _DEBUG
  26.  
  27. #define _FNAME "debug_"
  28.  
  29. #else
  30.  
  31. #define _FNAME "release_"
  32.  
  33. #endif
  34.  
  35. typedef struct _ElemType1
  36.  
  37. {
  38.  
  39. 	DWORD dw;
  40.  
  41. 	_ElemType1(DWORD _dw=0):dw(_dw)
  42.  
  43. 	{
  44.  
  45. 	}
  46.  
  47. 	bool operator<(_ElemType1 const &t1) const
  48.  
  49. 	{
  50.  
  51. 		return this->dw<t1.dw;
  52.  
  53. 	}
  54.  
  55. }ElemType1;
  56.  
  57. typedef struct _ElemType2
  58.  
  59. {
  60.  
  61. 	string str;
  62.  
  63. 	_ElemType2(string _str=""):str(_str)
  64.  
  65. 	{
  66.  
  67. 	}
  68.  
  69. 	bool operator<(_ElemType2 const &t1) const
  70.  
  71. 	{
  72.  
  73. 		return this->str<t1.str;
  74.  
  75. 	}
  76.  
  77. }ElemType2;
  78.  
  79. void test1_int_i(ofstream &of);
  80.  
  81. void test1_dword_i(ofstream &of);
  82.  
  83. void test2_vec_type1(ofstream &of);
  84.  
  85. void test2_vec_type2(ofstream &of);
  86.  
  87. void test3_list_type1(ofstream &of);
  88.  
  89. void test3_list_type2(ofstream &of);
  90.  
  91. void test4_set_type1(ofstream &of);
  92.  
  93. void test4_set_type2(ofstream &of);
  94.  
  95. void test5_map_type1(ofstream &of);
  96.  
  97. void test5_map_type2(ofstream &of);
  98.  
  99. void test1_int_i(ofstream &of)
  100.  
  101. {
  102.  
  103. 	volatile int i=0,j=0;
  104.  
  105. 	DWORD dw1,dw2,total=0;
  106.  
  107. 	cout<<"int类型:"<<endl;
  108.  
  109. 	of<<"int类型:"<<endl;
  110.  
  111. 	cout<<"i++测试:"<<endl;
  112.  
  113. 	of<<"i++测试:"<<endl;
  114.  
  115. 	for(;j<NUM1;++j)
  116.  
  117. 	{
  118.  
  119. 		dw1 = ::GetTickCount();
  120.  
  121. 		while (i<NUM2)
  122.  
  123. 		{
  124.  
  125. 			i++;
  126.  
  127. 		}
  128.  
  129. 		dw2 = ::GetTickCount();
  130.  
  131. 		i=0;
  132.  
  133. 		cout<<j<<" : "<<dw2-dw1<<endl;
  134.  
  135. 		of<<j<<" : "<<dw2-dw1<<endl;
  136.  
  137. 		total+=dw2-dw1;
  138.  
  139. 	}
  140.  
  141. 	cout<<"总消耗:"<<total<<endl;
  142.  
  143. 	of<<"总消耗:"<<total<<endl;
  144.  
  145. 	cout<<"平均消耗:"<<float(total)/NUM1<<endl;
  146.  
  147. 	of<<"平均消耗:"<<float(total)/NUM1<<endl;
  148.  
  149. 	cout<<endl;
  150.  
  151. 	of<<endl;
  152.  
  153. 	i = j = 0;
  154.  
  155. 	total = 0;
  156.  
  157. 	cout<<"++i测试:"<<endl;
  158.  
  159. 	of<<"++i测试:"<<endl;
  160.  
  161. 	for(;j<NUM1;++j)
  162.  
  163. 	{
  164.  
  165. 		dw1 = ::GetTickCount();
  166.  
  167. 		while (i<NUM2)
  168.  
  169. 		{
  170.  
  171. 			++i;
  172.  
  173. 		}
  174.  
  175. 		dw2 = ::GetTickCount();
  176.  
  177. 		i=0;
  178.  
  179. 		cout<<j<<" : "<<dw2-dw1<<endl;
  180.  
  181. 		of<<j<<" : "<<dw2-dw1<<endl;
  182.  
  183. 		total+=dw2-dw1;
  184.  
  185. 	}
  186.  
  187. 	cout<<"总消耗:"<<total<<endl;
  188.  
  189. 	of<<"总消耗:"<<total<<endl;
  190.  
  191. 	cout<<"平均消耗:"<<float(total)/NUM1<<endl;
  192.  
  193. 	of<<"平均消耗:"<<float(total)/NUM1<<endl;
  194.  
  195. 	cout<<endl;
  196.  
  197. 	of<<endl;
  198.  
  199. }
  200.  
  201. void test1_dword_i(ofstream &of)
  202.  
  203. {
  204.  
  205. 	volatile DWORD i=0,j=0;
  206.  
  207. 	DWORD dw1,dw2,total=0;
  208.  
  209. 	cout<<"DWORD类型:"<<endl;
  210.  
  211. 	of<<"DWORD类型:"<<endl;
  212.  
  213. 	cout<<"i++测试:"<<endl;
  214.  
  215. 	of<<"i++测试:"<<endl;
  216.  
  217. 	for(;j<NUM1;++j)
  218.  
  219. 	{
  220.  
  221. 		dw1 = ::GetTickCount();
  222.  
  223. 		while (i<NUM2)
  224.  
  225. 		{
  226.  
  227. 			i++;
  228.  
  229. 		}
  230.  
  231. 		dw2 = ::GetTickCount();
  232.  
  233. 		i=0;
  234.  
  235. 		cout<<j<<" : "<<dw2-dw1<<endl;
  236.  
  237. 		of<<j<<" : "<<dw2-dw1<<endl;
  238.  
  239. 		total+=dw2-dw1;
  240.  
  241. 	}
  242.  
  243. 	cout<<"总消耗:"<<total<<endl;
  244.  
  245. 	of<<"总消耗:"<<total<<endl;
  246.  
  247. 	cout<<"平均消耗:"<<float(total)/NUM1<<endl;
  248.  
  249. 	of<<"平均消耗:"<<float(total)/NUM1<<endl;
  250.  
  251. 	cout<<endl;
  252.  
  253. 	of<<endl;
  254.  
  255. 	i = j = 0;
  256.  
  257. 	total = 0;
  258.  
  259. 	cout<<"++i测试:"<<endl;
  260.  
  261. 	of<<"++i测试:"<<endl;
  262.  
  263. 	for(;j<NUM1;++j)
  264.  
  265. 	{
  266.  
  267. 		dw1 = ::GetTickCount();
  268.  
  269. 		while (i<NUM2)
  270.  
  271. 		{
  272.  
  273. 			++i;
  274.  
  275. 		}
  276.  
  277. 		dw2 = ::GetTickCount();
  278.  
  279. 		i=0;
  280.  
  281. 		cout<<j<<" : "<<dw2-dw1<<endl;
  282.  
  283. 		of<<j<<" : "<<dw2-dw1<<endl;
  284.  
  285. 		total+=dw2-dw1;
  286.  
  287. 	}
  288.  
  289. 	cout<<"总消耗:"<<total<<endl;
  290.  
  291. 	of<<"总消耗:"<<total<<endl;
  292.  
  293. 	cout<<"平均消耗:"<<float(total)/NUM1<<endl;
  294.  
  295. 	of<<"平均消耗:"<<float(total)/NUM1<<endl;
  296.  
  297. 	cout<<endl;
  298.  
  299. 	of<<endl;
  300.  
  301. }
  302.  
  303. DWORD g_dwFlag=0;
  304.  
  305. void test2_vec_type1(ofstream &of)
  306.  
  307. {
  308.  
  309. 	ElemType1 t1;
  310.  
  311. 	vector<ElemType1> vec1(NUM3,t1);
  312.  
  313. 	DWORD dw1,dw2,total=0;
  314.  
  315. 	cout<<"vector,使用type1:"<<endl;
  316.  
  317. 	of<<"vector,使用type1:"<<endl;
  318.  
  319. 	cout<<"iter++测试:"<<endl;
  320.  
  321. 	of<<"iter++测试:"<<endl;
  322.  
  323. 	int i = 0,j=0;
  324.  
  325. 	vector<ElemType1>::iterator iter;
  326.  
  327. 	vector<ElemType1>::const_iterator citer;
  328.  
  329. 	for(;i<NUM1;++i)
  330.  
  331. 	{
  332.  
  333. 		iter = vec1.begin();
  334.  
  335. 		dw1 = ::GetTickCount();
  336.  
  337. 		while (iter!=vec1.end())
  338.  
  339. 		{
  340.  
  341. #ifdef NDEBUG
  342.  
  343. g_dwFlag+=i;
  344.  
  345. #endif
  346.  
  347. 			iter++;
  348.  
  349. 		}
  350.  
  351. 		dw2 = ::GetTickCount();
  352.  
  353. 		cout<<i<<" : "<<dw2-dw1<<endl;
  354.  
  355. 		of<<i<<" : "<<dw2-dw1<<endl;
  356.  
  357. 		total+=dw2-dw1;
  358.  
  359. 	}
  360.  
  361. 	cout<<"总消耗:"<<total<<endl;
  362.  
  363. 	of<<"总消耗:"<<total<<endl;
  364.  
  365. 	cout<<"平均消耗:"<<float(total)/NUM1<<endl;
  366.  
  367. 	of<<"平均消耗:"<<float(total)/NUM1<<endl;
  368.  
  369. 	cout<<endl;
  370.  
  371. 	of<<endl;
  372.  
  373. 	i=0;
  374.  
  375. 	total=0;
  376.  
  377. 	cout<<"++iter测试:"<<endl;
  378.  
  379. 	of<<"++iter测试:"<<endl;
  380.  
  381. 	for(;i<NUM1;++i)
  382.  
  383. 	{
  384.  
  385. 		dw1 = ::GetTickCount();
  386.  
  387. 		iter = vec1.begin();
  388.  
  389. 		while (iter!=vec1.end())
  390.  
  391. 		{
  392.  
  393. #ifdef NDEBUG
  394.  
  395. 			g_dwFlag+=i;
  396.  
  397. #endif
  398.  
  399. 			++iter;
  400.  
  401. 		}
  402.  
  403. 		dw2 = ::GetTickCount();
  404.  
  405. 		cout<<i<<" : "<<dw2-dw1<<endl;
  406.  
  407. 		of<<i<<" : "<<dw2-dw1<<endl;
  408.  
  409. 		total+=dw2-dw1;
  410.  
  411. 	}
  412.  
  413. 	cout<<"总消耗:"<<total<<endl;
  414.  
  415. 	of<<"总消耗:"<<total<<endl;
  416.  
  417. 	cout<<"平均消耗:"<<float(total)/NUM1<<endl;
  418.  
  419. 	of<<"平均消耗:"<<float(total)/NUM1<<endl;
  420.  
  421. 	cout<<endl;
  422.  
  423. 	of<<endl;
  424.  
  425. 	i=0;
  426.  
  427. 	total=0;
  428.  
  429. 	cout<<"citer++测试:"<<endl;
  430.  
  431. 	of<<"citer++测试:"<<endl;
  432.  
  433. 	for(;i<NUM1;++i)
  434.  
  435. 	{
  436.  
  437. 		dw1 = ::GetTickCount();
  438.  
  439. 		citer = vec1.begin();
  440.  
  441. 		while (citer!=vec1.end())
  442.  
  443. 		{
  444.  
  445. #ifdef NDEBUG
  446.  
  447. 			g_dwFlag+=i;
  448.  
  449. #endif
  450.  
  451. 			citer++;
  452.  
  453. 		}
  454.  
  455. 		dw2 = ::GetTickCount();
  456.  
  457. 		cout<<i<<" : "<<dw2-dw1<<endl;
  458.  
  459. 		of<<i<<" : "<<dw2-dw1<<endl;
  460.  
  461. 		total+=dw2-dw1;
  462.  
  463. 	}
  464.  
  465. 	cout<<"总消耗:"<<total<<endl;
  466.  
  467. 	of<<"总消耗:"<<total<<endl;
  468.  
  469. 	cout<<"平均消耗:"<<float(total)/NUM1<<endl;
  470.  
  471. 	of<<"平均消耗:"<<float(total)/NUM1<<endl;
  472.  
  473. 	cout<<endl;
  474.  
  475. 	of<<endl;
  476.  
  477. 	i=0;
  478.  
  479. 	total=0;
  480.  
  481. 	cout<<"++citer测试:"<<endl;
  482.  
  483. 	of<<"++citer测试:"<<endl;
  484.  
  485. 	for(;i<NUM1;++i)
  486.  
  487. 	{
  488.  
  489. 		dw1 = ::GetTickCount();
  490.  
  491. 		citer = vec1.begin();
  492.  
  493. 		while (citer!=vec1.end())
  494.  
  495. 		{
  496.  
  497. #ifdef NDEBUG
  498.  
  499. 			g_dwFlag+=i;
  500.  
  501. #endif
  502.  
  503. 			++citer;
  504.  
  505. 		}
  506.  
  507. 		dw2 = ::GetTickCount();
  508.  
  509. 		cout<<i<<" : "<<dw2-dw1<<endl;
  510.  
  511. 		of<<i<<" : "<<dw2-dw1<<endl;
  512.  
  513. 		total+=dw2-dw1;
  514.  
  515. 	}
  516.  
  517. 	cout<<"总消耗:"<<total<<endl;
  518.  
  519. 	of<<"总消耗:"<<total<<endl;
  520.  
  521. 	cout<<"平均消耗:"<<float(total)/NUM1<<endl;
  522.  
  523. 	of<<"平均消耗:"<<float(total)/NUM1<<endl;
  524.  
  525. 	cout<<endl;
  526.  
  527. 	of<<endl;
  528.  
  529. }
  530.  
  531. void test2_vec_type2(ofstream &of)
  532.  
  533. {
  534.  
  535. 	ElemType2 t2;
  536.  
  537. 	vector<ElemType2> vec1(NUM3,t2);
  538.  
  539. 	DWORD dw1,dw2,total=0;
  540.  
  541. 	cout<<"vector,使用type2:"<<endl;
  542.  
  543. 	of<<"vector,使用type2:"<<endl;
  544.  
  545. 	cout<<"iter++测试:"<<endl;
  546.  
  547. 	of<<"iter++测试:"<<endl;
  548.  
  549. 	int i = 0,j=0;
  550.  
  551. 	vector<ElemType2>::iterator iter;
  552.  
  553. 	vector<ElemType2>::const_iterator citer;
  554.  
  555. 	for(;i<NUM1;++i)
  556.  
  557. 	{
  558.  
  559. 		dw1 = ::GetTickCount();
  560.  
  561. 		iter = vec1.begin();
  562.  
  563. 		while (iter!=vec1.end())
  564.  
  565. 		{
  566.  
  567. #ifdef NDEBUG
  568.  
  569. 			g_dwFlag+=i;
  570.  
  571. #endif
  572.  
  573. 			iter++;
  574.  
  575. 		}
  576.  
  577. 		dw2 = ::GetTickCount();
  578.  
  579. 		cout<<i<<" : "<<dw2-dw1<<endl;
  580.  
  581. 		of<<i<<" : "<<dw2-dw1<<endl;
  582.  
  583. 		total+=dw2-dw1;
  584.  
  585. 	}
  586.  
  587. 	cout<<"总消耗:"<<total<<endl;
  588.  
  589. 	of<<"总消耗:"<<total<<endl;
  590.  
  591. 	cout<<"平均消耗:"<<float(total)/NUM1<<endl;
  592.  
  593. 	of<<"平均消耗:"<<float(total)/NUM1<<endl;
  594.  
  595. 	cout<<endl;
  596.  
  597. 	of<<endl;
  598.  
  599. 	i=0;
  600.  
  601. 	total=0;
  602.  
  603. 	cout<<"++iter测试:"<<endl;
  604.  
  605. 	of<<"++iter测试:"<<endl;
  606.  
  607. 	for(;i<NUM1;++i)
  608.  
  609. 	{
  610.  
  611. 		dw1 = ::GetTickCount();
  612.  
  613. 		iter = vec1.begin();
  614.  
  615. 		while (iter!=vec1.end())
  616.  
  617. 		{
  618.  
  619. #ifdef NDEBUG
  620.  
  621. 			g_dwFlag+=i;
  622.  
  623. #endif
  624.  
  625. 			++iter;
  626.  
  627. 		}
  628.  
  629. 		dw2 = ::GetTickCount();
  630.  
  631. 		cout<<i<<" : "<<dw2-dw1<<endl;
  632.  
  633. 		of<<i<<" : "<<dw2-dw1<<endl;
  634.  
  635. 		total+=dw2-dw1;
  636.  
  637. 	}
  638.  
  639. 	cout<<"总消耗:"<<total<<endl;
  640.  
  641. 	of<<"总消耗:"<<total<<endl;
  642.  
  643. 	cout<<"平均消耗:"<<float(total)/NUM1<<endl;
  644.  
  645. 	of<<"平均消耗:"<<float(total)/NUM1<<endl;
  646.  
  647. 	cout<<endl;
  648.  
  649. 	of<<endl;
  650.  
  651. 	i=0;
  652.  
  653. 	total=0;
  654.  
  655. 	cout<<"citer++测试:"<<endl;
  656.  
  657. 	of<<"citer++测试:"<<endl;
  658.  
  659. 	for(;i<NUM1;++i)
  660.  
  661. 	{
  662.  
  663. 		dw1 = ::GetTickCount();
  664.  
  665. 		citer = vec1.begin();
  666.  
  667. 		while (citer!=vec1.end())
  668.  
  669. 		{
  670.  
  671. #ifdef NDEBUG
  672.  
  673. 			g_dwFlag+=i;
  674.  
  675. #endif
  676.  
  677. 			citer++;
  678.  
  679. 		}
  680.  
  681. 		dw2 = ::GetTickCount();
  682.  
  683. 		cout<<i<<" : "<<dw2-dw1<<endl;
  684.  
  685. 		of<<i<<" : "<<dw2-dw1<<endl;
  686.  
  687. 		total+=dw2-dw1;
  688.  
  689. 	}
  690.  
  691. 	cout<<"总消耗:"<<total<<endl;
  692.  
  693. 	of<<"总消耗:"<<total<<endl;
  694.  
  695. 	cout<<"平均消耗:"<<float(total)/NUM1<<endl;
  696.  
  697. 	of<<"平均消耗:"<<float(total)/NUM1<<endl;
  698.  
  699. 	cout<<endl;
  700.  
  701. 	of<<endl;
  702.  
  703. 	i=0;
  704.  
  705. 	total=0;
  706.  
  707. 	cout<<"++citer测试:"<<endl;
  708.  
  709. 	of<<"++citer测试:"<<endl;
  710.  
  711. 	for(;i<NUM1;++i)
  712.  
  713. 	{
  714.  
  715. 		dw1 = ::GetTickCount();
  716.  
  717. 		citer = vec1.begin();
  718.  
  719. 		while (citer!=vec1.end())
  720.  
  721. 		{
  722.  
  723. #ifdef NDEBUG
  724.  
  725. 			g_dwFlag+=i;
  726.  
  727. #endif
  728.  
  729. 			++citer;
  730.  
  731. 		}
  732.  
  733. 		dw2 = ::GetTickCount();
  734.  
  735. 		cout<<i<<" : "<<dw2-dw1<<endl;
  736.  
  737. 		of<<i<<" : "<<dw2-dw1<<endl;
  738.  
  739. 		total+=dw2-dw1;
  740.  
  741. 	}
  742.  
  743. 	cout<<"总消耗:"<<total<<endl;
  744.  
  745. 	of<<"总消耗:"<<total<<endl;
  746.  
  747. 	cout<<"平均消耗:"<<float(total)/NUM1<<endl;
  748.  
  749. 	of<<"平均消耗:"<<float(total)/NUM1<<endl;
  750.  
  751. 	cout<<endl;
  752.  
  753. 	of<<endl;
  754.  
  755. }
  756.  
  757. void test3_list_type1(ofstream &of)
  758.  
  759. {
  760.  
  761. 	ElemType1 t1;
  762.  
  763. 	list<ElemType1> ls(NUM3,t1);
  764.  
  765. 	DWORD dw1,dw2,total=0;
  766.  
  767. 	cout<<"list,使用type1:"<<endl;
  768.  
  769. 	of<<"list,使用type1:"<<endl;
  770.  
  771. 	cout<<"iter++测试:"<<endl;
  772.  
  773. 	of<<"iter++测试:"<<endl;
  774.  
  775. 	int i = 0,j=0;
  776.  
  777. 	list<ElemType1>::iterator iter;
  778.  
  779. 	list<ElemType1>::const_iterator citer;
  780.  
  781. 	for(;i<NUM1;++i)
  782.  
  783. 	{
  784.  
  785. 		dw1 = ::GetTickCount();
  786.  
  787. 		iter = ls.begin();
  788.  
  789. 		while (iter!=ls.end())
  790.  
  791. 		{
  792.  
  793. #ifdef NDEBUG
  794.  
  795. 			g_dwFlag+=i;
  796.  
  797. #endif
  798.  
  799. 			iter++;
  800.  
  801. 		}
  802.  
  803. 		dw2 = ::GetTickCount();
  804.  
  805. 		cout<<i<<" : "<<dw2-dw1<<endl;
  806.  
  807. 		of<<i<<" : "<<dw2-dw1<<endl;
  808.  
  809. 		total+=dw2-dw1;
  810.  
  811. 	}
  812.  
  813. 	cout<<"总消耗:"<<total<<endl;
  814.  
  815. 	of<<"总消耗:"<<total<<endl;
  816.  
  817. 	cout<<"平均消耗:"<<float(total)/NUM1<<endl;
  818.  
  819. 	of<<"平均消耗:"<<float(total)/NUM1<<endl;
  820.  
  821. 	cout<<endl;
  822.  
  823. 	of<<endl;
  824.  
  825. 	i=0;
  826.  
  827. 	total=0;
  828.  
  829. 	cout<<"++iter测试:"<<endl;
  830.  
  831. 	of<<"++iter测试:"<<endl;
  832.  
  833. 	for(;i<NUM1;++i)
  834.  
  835. 	{
  836.  
  837. 		dw1 = ::GetTickCount();
  838.  
  839. 		iter = ls.begin();
  840.  
  841. 		while (iter!=ls.end())
  842.  
  843. 		{
  844.  
  845. #ifdef NDEBUG
  846.  
  847. 			g_dwFlag+=i;
  848.  
  849. #endif
  850.  
  851. 			++iter;
  852.  
  853. 		}
  854.  
  855. 		dw2 = ::GetTickCount();
  856.  
  857. 		cout<<i<<" : "<<dw2-dw1<<endl;
  858.  
  859. 		of<<i<<" : "<<dw2-dw1<<endl;
  860.  
  861. 		total+=dw2-dw1;
  862.  
  863. 	}
  864.  
  865. 	cout<<"总消耗:"<<total<<endl;
  866.  
  867. 	of<<"总消耗:"<<total<<endl;
  868.  
  869. 	cout<<"平均消耗:"<<float(total)/NUM1<<endl;
  870.  
  871. 	of<<"平均消耗:"<<float(total)/NUM1<<endl;
  872.  
  873. 	cout<<endl;
  874.  
  875. 	of<<endl;
  876.  
  877. 	i=0;
  878.  
  879. 	total=0;
  880.  
  881. 	cout<<"citer++测试:"<<endl;
  882.  
  883. 	of<<"citer++测试:"<<endl;
  884.  
  885. 	for(;i<NUM1;++i)
  886.  
  887. 	{
  888.  
  889. 		dw1 = ::GetTickCount();
  890.  
  891. 		citer = ls.begin();
  892.  
  893. 		while (citer!=ls.end())
  894.  
  895. 		{
  896.  
  897. #ifdef NDEBUG
  898.  
  899. 			g_dwFlag+=i;
  900.  
  901. #endif
  902.  
  903. 			citer++;
  904.  
  905. 		}
  906.  
  907. 		dw2 = ::GetTickCount();
  908.  
  909. 		cout<<i<<" : "<<dw2-dw1<<endl;
  910.  
  911. 		of<<i<<" : "<<dw2-dw1<<endl;
  912.  
  913. 		total+=dw2-dw1;
  914.  
  915. 	}
  916.  
  917. 	cout<<"总消耗:"<<total<<endl;
  918.  
  919. 	of<<"总消耗:"<<total<<endl;
  920.  
  921. 	cout<<"平均消耗:"<<float(total)/NUM1<<endl;
  922.  
  923. 	of<<"平均消耗:"<<float(total)/NUM1<<endl;
  924.  
  925. 	cout<<endl;
  926.  
  927. 	of<<endl;
  928.  
  929. 	i=0;
  930.  
  931. 	total=0;
  932.  
  933. 	cout<<"++citer测试:"<<endl;
  934.  
  935. 	of<<"++citer测试:"<<endl;
  936.  
  937. 	for(;i<NUM1;++i)
  938.  
  939. 	{
  940.  
  941. 		dw1 = ::GetTickCount();
  942.  
  943. 		citer = ls.begin();
  944.  
  945. 		while (citer!=ls.end())
  946.  
  947. 		{
  948.  
  949. #ifdef NDEBUG
  950.  
  951. 			g_dwFlag+=i;
  952.  
  953. #endif
  954.  
  955. 			++citer;
  956.  
  957. 		}
  958.  
  959. 		dw2 = ::GetTickCount();
  960.  
  961. 		cout<<i<<" : "<<dw2-dw1<<endl;
  962.  
  963. 		of<<i<<" : "<<dw2-dw1<<endl;
  964.  
  965. 		total+=dw2-dw1;
  966.  
  967. 	}
  968.  
  969. 	cout<<"总消耗:"<<total<<endl;
  970.  
  971. 	of<<"总消耗:"<<total<<endl;
  972.  
  973. 	cout<<"平均消耗:"<<float(total)/NUM1<<endl;
  974.  
  975. 	of<<"平均消耗:"<<float(total)/NUM1<<endl;
  976.  
  977. 	cout<<endl;
  978.  
  979. 	of<<endl;
  980.  
  981. }
  982.  
  983. void test3_list_type2(ofstream &of)
  984.  
  985. {
  986.  
  987. 	ElemType2 t2;
  988.  
  989. 	list<ElemType2> ls(NUM3,t2);
  990.  
  991. 	DWORD dw1,dw2,total=0;
  992.  
  993. 	cout<<"list,使用type2:"<<endl;
  994.  
  995. 	of<<"list,使用type2:"<<endl;
  996.  
  997. 	cout<<"iter++测试:"<<endl;
  998.  
  999. 	of<<"iter++测试:"<<endl;
  1000.  
  1001. 	int i = 0,j=0;
  1002.  
  1003. 	list<ElemType2>::iterator iter;
  1004.  
  1005. 	list<ElemType2>::const_iterator citer;
  1006.  
  1007. 	for(;i<NUM1;++i)
  1008.  
  1009. 	{
  1010.  
  1011. 		dw1 = ::GetTickCount();
  1012.  
  1013. 		iter = ls.begin();
  1014.  
  1015. 		while (iter!=ls.end())
  1016.  
  1017. 		{
  1018.  
  1019. #ifdef NDEBUG
  1020.  
  1021. 			g_dwFlag+=i;
  1022.  
  1023. #endif
  1024.  
  1025. 			iter++;
  1026.  
  1027. 		}
  1028.  
  1029. 		dw2 = ::GetTickCount();
  1030.  
  1031. 		cout<<i<<" : "<<dw2-dw1<<endl;
  1032.  
  1033. 		of<<i<<" : "<<dw2-dw1<<endl;
  1034.  
  1035. 		total+=dw2-dw1;
  1036.  
  1037. 	}
  1038.  
  1039. 	cout<<"总消耗:"<<total<<endl;
  1040.  
  1041. 	of<<"总消耗:"<<total<<endl;
  1042.  
  1043. 	cout<<"平均消耗:"<<float(total)/NUM1<<endl;
  1044.  
  1045. 	of<<"平均消耗:"<<float(total)/NUM1<<endl;
  1046.  
  1047. 	cout<<endl;
  1048.  
  1049. 	of<<endl;
  1050.  
  1051. 	i=0;
  1052.  
  1053. 	total=0;
  1054.  
  1055. 	cout<<"++iter测试:"<<endl;
  1056.  
  1057. 	of<<"++iter测试:"<<endl;
  1058.  
  1059. 	for(;i<NUM1;++i)
  1060.  
  1061. 	{
  1062.  
  1063. 		dw1 = ::GetTickCount();
  1064.  
  1065. 		iter = ls.begin();
  1066.  
  1067. 		while (iter!=ls.end())
  1068.  
  1069. 		{
  1070.  
  1071. #ifdef NDEBUG
  1072.  
  1073. 			g_dwFlag+=i;
  1074.  
  1075. #endif
  1076.  
  1077. 			++iter;
  1078.  
  1079. 		}
  1080.  
  1081. 		dw2 = ::GetTickCount();
  1082.  
  1083. 		cout<<i<<" : "<<dw2-dw1<<endl;
  1084.  
  1085. 		of<<i<<" : "<<dw2-dw1<<endl;
  1086.  
  1087. 		total+=dw2-dw1;
  1088.  
  1089. 	}
  1090.  
  1091. 	cout<<"总消耗:"<<total<<endl;
  1092.  
  1093. 	of<<"总消耗:"<<total<<endl;
  1094.  
  1095. 	cout<<"平均消耗:"<<float(total)/NUM1<<endl;
  1096.  
  1097. 	of<<"平均消耗:"<<float(total)/NUM1<<endl;
  1098.  
  1099. 	cout<<endl;
  1100.  
  1101. 	of<<endl;
  1102.  
  1103. 	i=0;
  1104.  
  1105. 	total=0;
  1106.  
  1107. 	cout<<"citer++测试:"<<endl;
  1108.  
  1109. 	of<<"citer++测试:"<<endl;
  1110.  
  1111. 	for(;i<NUM1;++i)
  1112.  
  1113. 	{
  1114.  
  1115. 		dw1 = ::GetTickCount();
  1116.  
  1117. 		citer = ls.begin();
  1118.  
  1119. 		while (citer!=ls.end())
  1120.  
  1121. 		{
  1122.  
  1123. #ifdef NDEBUG
  1124.  
  1125. 			g_dwFlag+=i;
  1126.  
  1127. #endif
  1128.  
  1129. 			citer++;
  1130.  
  1131. 		}
  1132.  
  1133. 		dw2 = ::GetTickCount();
  1134.  
  1135. 		cout<<i<<" : "<<dw2-dw1<<endl;
  1136.  
  1137. 		of<<i<<" : "<<dw2-dw1<<endl;
  1138.  
  1139. 		total+=dw2-dw1;
  1140.  
  1141. 	}
  1142.  
  1143. 	cout<<"总消耗:"<<total<<endl;
  1144.  
  1145. 	of<<"总消耗:"<<total<<endl;
  1146.  
  1147. 	cout<<"平均消耗:"<<float(total)/NUM1<<endl;
  1148.  
  1149. 	of<<"平均消耗:"<<float(total)/NUM1<<endl;
  1150.  
  1151. 	cout<<endl;
  1152.  
  1153. 	of<<endl;
  1154.  
  1155. 	i=0;
  1156.  
  1157. 	total=0;
  1158.  
  1159. 	cout<<"++citer测试:"<<endl;
  1160.  
  1161. 	of<<"++citer测试:"<<endl;
  1162.  
  1163. 	for(;i<NUM1;++i)
  1164.  
  1165. 	{
  1166.  
  1167. 		dw1 = ::GetTickCount();
  1168.  
  1169. 		citer = ls.begin();
  1170.  
  1171. 		while (citer!=ls.end())
  1172.  
  1173. 		{
  1174.  
  1175. #ifdef NDEBUG
  1176.  
  1177. 			g_dwFlag+=i;
  1178.  
  1179. #endif
  1180.  
  1181. 			++citer;
  1182.  
  1183. 		}
  1184.  
  1185. 		dw2 = ::GetTickCount();
  1186.  
  1187. 		cout<<i<<" : "<<dw2-dw1<<endl;
  1188.  
  1189. 		of<<i<<" : "<<dw2-dw1<<endl;
  1190.  
  1191. 		total+=dw2-dw1;
  1192.  
  1193. 	}
  1194.  
  1195. 	cout<<"总消耗:"<<total<<endl;
  1196.  
  1197. 	of<<"总消耗:"<<total<<endl;
  1198.  
  1199. 	cout<<"平均消耗:"<<float(total)/NUM1<<endl;
  1200.  
  1201. 	of<<"平均消耗:"<<float(total)/NUM1<<endl;
  1202.  
  1203. 	cout<<endl;
  1204.  
  1205. 	of<<endl;
  1206.  
  1207. }
  1208.  
  1209. void test4_set_type1(ofstream &of)
  1210.  
  1211. {
  1212.  
  1213. 	set<ElemType1> ls;
  1214.  
  1215. 	for (int n=0;n<NUM3;++n)
  1216.  
  1217. 	{
  1218.  
  1219. 		ls.insert(_ElemType1(n));
  1220.  
  1221. 	}
  1222.  
  1223. 	DWORD dw1,dw2,total=0;
  1224.  
  1225. 	cout<<"set,使用type1:"<<endl;
  1226.  
  1227. 	of<<"set,使用type1:"<<endl;
  1228.  
  1229. 	cout<<"iter++测试:"<<endl;
  1230.  
  1231. 	of<<"iter++测试:"<<endl;
  1232.  
  1233. 	int i = 0,j=0;
  1234.  
  1235. 	set<ElemType1>::iterator iter;
  1236.  
  1237. 	set<ElemType1>::const_iterator citer;
  1238.  
  1239. 	for(;i<NUM1;++i)
  1240.  
  1241. 	{
  1242.  
  1243. 		iter = ls.begin();
  1244.  
  1245. 		dw1 = ::GetTickCount();
  1246.  
  1247. 		while (iter!=ls.end())
  1248.  
  1249. 		{
  1250.  
  1251. 			iter++;
  1252.  
  1253. 		}
  1254.  
  1255. 		dw2 = ::GetTickCount();
  1256.  
  1257. 		cout<<i<<" : "<<dw2-dw1<<endl;
  1258.  
  1259. 		of<<i<<" : "<<dw2-dw1<<endl;
  1260.  
  1261. 		total+=dw2-dw1;
  1262.  
  1263. 	}
  1264.  
  1265. 	cout<<"总消耗:"<<total<<endl;
  1266.  
  1267. 	of<<"总消耗:"<<total<<endl;
  1268.  
  1269. 	cout<<"平均消耗:"<<float(total)/NUM1<<endl;
  1270.  
  1271. 	of<<"平均消耗:"<<float(total)/NUM1<<endl;
  1272.  
  1273. 	cout<<endl;
  1274.  
  1275. 	of<<endl;
  1276.  
  1277. 	i=0;
  1278.  
  1279. 	total=0;
  1280.  
  1281. 	cout<<"++iter测试:"<<endl;
  1282.  
  1283. 	of<<"++iter测试:"<<endl;
  1284.  
  1285. 	for(;i<NUM1;++i)
  1286.  
  1287. 	{
  1288.  
  1289. 		iter = ls.begin();
  1290.  
  1291. 		dw1 = ::GetTickCount();
  1292.  
  1293. 		while (iter!=ls.end())
  1294.  
  1295. 		{
  1296.  
  1297. 			++iter;
  1298.  
  1299. 		}
  1300.  
  1301. 		dw2 = ::GetTickCount();
  1302.  
  1303. 		cout<<i<<" : "<<dw2-dw1<<endl;
  1304.  
  1305. 		of<<i<<" : "<<dw2-dw1<<endl;
  1306.  
  1307. 		total+=dw2-dw1;
  1308.  
  1309. 	}
  1310.  
  1311. 	cout<<"总消耗:"<<total<<endl;
  1312.  
  1313. 	of<<"总消耗:"<<total<<endl;
  1314.  
  1315. 	cout<<"平均消耗:"<<float(total)/NUM1<<endl;
  1316.  
  1317. 	of<<"平均消耗:"<<float(total)/NUM1<<endl;
  1318.  
  1319. 	cout<<endl;
  1320.  
  1321. 	of<<endl;
  1322.  
  1323. 	i=0;
  1324.  
  1325. 	total=0;
  1326.  
  1327. 	cout<<"citer++测试:"<<endl;
  1328.  
  1329. 	of<<"citer++测试:"<<endl;
  1330.  
  1331. 	for(;i<NUM1;++i)
  1332.  
  1333. 	{
  1334.  
  1335. 		citer = ls.begin();
  1336.  
  1337. 		dw1 = ::GetTickCount();
  1338.  
  1339. 		while (citer!=ls.end())
  1340.  
  1341. 		{
  1342.  
  1343. 			citer++;
  1344.  
  1345. 		}
  1346.  
  1347. 		dw2 = ::GetTickCount();
  1348.  
  1349. 		cout<<i<<" : "<<dw2-dw1<<endl;
  1350.  
  1351. 		of<<i<<" : "<<dw2-dw1<<endl;
  1352.  
  1353. 		total+=dw2-dw1;
  1354.  
  1355. 	}
  1356.  
  1357. 	cout<<"总消耗:"<<total<<endl;
  1358.  
  1359. 	of<<"总消耗:"<<total<<endl;
  1360.  
  1361. 	cout<<"平均消耗:"<<float(total)/NUM1<<endl;
  1362.  
  1363. 	of<<"平均消耗:"<<float(total)/NUM1<<endl;
  1364.  
  1365. 	cout<<endl;
  1366.  
  1367. 	of<<endl;
  1368.  
  1369. 	i=0;
  1370.  
  1371. 	total=0;
  1372.  
  1373. 	cout<<"++citer测试:"<<endl;
  1374.  
  1375. 	of<<"++citer测试:"<<endl;
  1376.  
  1377. 	for(;i<NUM1;++i)
  1378.  
  1379. 	{
  1380.  
  1381. 		citer = ls.begin();
  1382.  
  1383. 		dw1 = ::GetTickCount();
  1384.  
  1385. 		while (citer!=ls.end())
  1386.  
  1387. 		{
  1388.  
  1389. 			++citer;
  1390.  
  1391. 		}
  1392.  
  1393. 		dw2 = ::GetTickCount();
  1394.  
  1395. 		cout<<i<<" : "<<dw2-dw1<<endl;
  1396.  
  1397. 		of<<i<<" : "<<dw2-dw1<<endl;
  1398.  
  1399. 		total+=dw2-dw1;
  1400.  
  1401. 	}
  1402.  
  1403. 	cout<<"总消耗:"<<total<<endl;
  1404.  
  1405. 	of<<"总消耗:"<<total<<endl;
  1406.  
  1407. 	cout<<"平均消耗:"<<float(total)/NUM1<<endl;
  1408.  
  1409. 	of<<"平均消耗:"<<float(total)/NUM1<<endl;
  1410.  
  1411. 	cout<<endl;
  1412.  
  1413. 	of<<endl;
  1414.  
  1415. }
  1416.  
  1417. void test4_set_type2(ofstream &of)
  1418.  
  1419. {
  1420.  
  1421. 	set<ElemType2> ls;
  1422.  
  1423. 	char sz[255];
  1424.  
  1425. 	for (int n=0;n<NUM3;++n)
  1426.  
  1427. 	{
  1428.  
  1429. 		itoa(n,sz,10);
  1430.  
  1431. 		ls.insert(ElemType2(sz));
  1432.  
  1433. 	}
  1434.  
  1435. 	DWORD dw1,dw2,total=0;
  1436.  
  1437. 	cout<<"set,使用type2:"<<endl;
  1438.  
  1439. 	of<<"set,使用type2:"<<endl;
  1440.  
  1441. 	cout<<"iter++测试:"<<endl;
  1442.  
  1443. 	of<<"iter++测试:"<<endl;
  1444.  
  1445. 	int i = 0,j=0;
  1446.  
  1447. 	set<ElemType2>::iterator iter;
  1448.  
  1449. 	set<ElemType2>::const_iterator citer;
  1450.  
  1451. 	for(;i<NUM1;++i)
  1452.  
  1453. 	{
  1454.  
  1455. 		iter = ls.begin();
  1456.  
  1457. 		dw1 = ::GetTickCount();
  1458.  
  1459. 		while (iter!=ls.end())
  1460.  
  1461. 		{
  1462.  
  1463. 			iter++;
  1464.  
  1465. 		}
  1466.  
  1467. 		dw2 = ::GetTickCount();
  1468.  
  1469. 		cout<<i<<" : "<<dw2-dw1<<endl;
  1470.  
  1471. 		of<<i<<" : "<<dw2-dw1<<endl;
  1472.  
  1473. 		total+=dw2-dw1;
  1474.  
  1475. 	}
  1476.  
  1477. 	cout<<"总消耗:"<<total<<endl;
  1478.  
  1479. 	of<<"总消耗:"<<total<<endl;
  1480.  
  1481. 	cout<<"平均消耗:"<<float(total)/NUM1<<endl;
  1482.  
  1483. 	of<<"平均消耗:"<<float(total)/NUM1<<endl;
  1484.  
  1485. 	cout<<endl;
  1486.  
  1487. 	of<<endl;
  1488.  
  1489. 	i=0;
  1490.  
  1491. 	total=0;
  1492.  
  1493. 	cout<<"++iter测试:"<<endl;
  1494.  
  1495. 	of<<"++iter测试:"<<endl;
  1496.  
  1497. 	for(;i<NUM1;++i)
  1498.  
  1499. 	{
  1500.  
  1501. 		iter = ls.begin();
  1502.  
  1503. 		dw1 = ::GetTickCount();
  1504.  
  1505. 		while (iter!=ls.end())
  1506.  
  1507. 		{
  1508.  
  1509. 			++iter;
  1510.  
  1511. 		}
  1512.  
  1513. 		dw2 = ::GetTickCount();
  1514.  
  1515. 		cout<<i<<" : "<<dw2-dw1<<endl;
  1516.  
  1517. 		of<<i<<" : "<<dw2-dw1<<endl;
  1518.  
  1519. 		total+=dw2-dw1;
  1520.  
  1521. 	}
  1522.  
  1523. 	cout<<"总消耗:"<<total<<endl;
  1524.  
  1525. 	of<<"总消耗:"<<total<<endl;
  1526.  
  1527. 	cout<<"平均消耗:"<<float(total)/NUM1<<endl;
  1528.  
  1529. 	of<<"平均消耗:"<<float(total)/NUM1<<endl;
  1530.  
  1531. 	cout<<endl;
  1532.  
  1533. 	of<<endl;
  1534.  
  1535. 	i=0;
  1536.  
  1537. 	total=0;
  1538.  
  1539. 	cout<<"citer++测试:"<<endl;
  1540.  
  1541. 	of<<"citer++测试:"<<endl;
  1542.  
  1543. 	for(;i<NUM1;++i)
  1544.  
  1545. 	{
  1546.  
  1547. 		citer = ls.begin();
  1548.  
  1549. 		dw1 = ::GetTickCount();
  1550.  
  1551. 		while (citer!=ls.end())
  1552.  
  1553. 		{
  1554.  
  1555. 			citer++;
  1556.  
  1557. 		}
  1558.  
  1559. 		dw2 = ::GetTickCount();
  1560.  
  1561. 		cout<<i<<" : "<<dw2-dw1<<endl;
  1562.  
  1563. 		of<<i<<" : "<<dw2-dw1<<endl;
  1564.  
  1565. 		total+=dw2-dw1;
  1566.  
  1567. 	}
  1568.  
  1569. 	cout<<"总消耗:"<<total<<endl;
  1570.  
  1571. 	of<<"总消耗:"<<total<<endl;
  1572.  
  1573. 	cout<<"平均消耗:"<<float(total)/NUM1<<endl;
  1574.  
  1575. 	of<<"平均消耗:"<<float(total)/NUM1<<endl;
  1576.  
  1577. 	cout<<endl;
  1578.  
  1579. 	of<<endl;
  1580.  
  1581. 	i=0;
  1582.  
  1583. 	total=0;
  1584.  
  1585. 	cout<<"++citer测试:"<<endl;
  1586.  
  1587. 	of<<"++citer测试:"<<endl;
  1588.  
  1589. 	for(;i<NUM1;++i)
  1590.  
  1591. 	{
  1592.  
  1593. 		citer = ls.begin();
  1594.  
  1595. 		dw1 = ::GetTickCount();
  1596.  
  1597. 		while (citer!=ls.end())
  1598.  
  1599. 		{
  1600.  
  1601. 			++citer;
  1602.  
  1603. 		}
  1604.  
  1605. 		dw2 = ::GetTickCount();
  1606.  
  1607. 		cout<<i<<" : "<<dw2-dw1<<endl;
  1608.  
  1609. 		of<<i<<" : "<<dw2-dw1<<endl;
  1610.  
  1611. 		total+=dw2-dw1;
  1612.  
  1613. 	}
  1614.  
  1615. 	cout<<"总消耗:"<<total<<endl;
  1616.  
  1617. 	of<<"总消耗:"<<total<<endl;
  1618.  
  1619. 	cout<<"平均消耗:"<<float(total)/NUM1<<endl;
  1620.  
  1621. 	of<<"平均消耗:"<<float(total)/NUM1<<endl;
  1622.  
  1623. 	cout<<endl;
  1624.  
  1625. 	of<<endl;
  1626.  
  1627. }
  1628.  
  1629. void test5_map_type1(ofstream &of)
  1630.  
  1631. {
  1632.  
  1633. 	map<int,ElemType1> ls;
  1634.  
  1635. 	for (int n=0;n<NUM3;++n)
  1636.  
  1637. 	{
  1638.  
  1639. 		ls.insert(pair<int,ElemType1>(n,ElemType1(n)));
  1640.  
  1641. 	}
  1642.  
  1643. 	DWORD dw1,dw2,total=0;
  1644.  
  1645. 	cout<<"map,使用type1:"<<endl;
  1646.  
  1647. 	of<<"map,使用type1:"<<endl;
  1648.  
  1649. 	cout<<"iter++测试:"<<endl;
  1650.  
  1651. 	of<<"iter++测试:"<<endl;
  1652.  
  1653. 	int i = 0,j=0;
  1654.  
  1655. 	map<int,ElemType1>::iterator iter;
  1656.  
  1657. 	map<int,ElemType1>::const_iterator citer;
  1658.  
  1659. 	for(;i<NUM1;++i)
  1660.  
  1661. 	{
  1662.  
  1663. 		iter = ls.begin();
  1664.  
  1665. 		dw1 = ::GetTickCount();
  1666.  
  1667. 		while (iter!=ls.end())
  1668.  
  1669. 		{
  1670.  
  1671. 			iter++;
  1672.  
  1673. 		}
  1674.  
  1675. 		dw2 = ::GetTickCount();
  1676.  
  1677. 		cout<<i<<" : "<<dw2-dw1<<endl;
  1678.  
  1679. 		of<<i<<" : "<<dw2-dw1<<endl;
  1680.  
  1681. 		total+=dw2-dw1;
  1682.  
  1683. 	}
  1684.  
  1685. 	cout<<"总消耗:"<<total<<endl;
  1686.  
  1687. 	of<<"总消耗:"<<total<<endl;
  1688.  
  1689. 	cout<<"平均消耗:"<<float(total)/NUM1<<endl;
  1690.  
  1691. 	of<<"平均消耗:"<<float(total)/NUM1<<endl;
  1692.  
  1693. 	cout<<endl;
  1694.  
  1695. 	of<<endl;
  1696.  
  1697. 	i=0;
  1698.  
  1699. 	total=0;
  1700.  
  1701. 	cout<<"++iter测试:"<<endl;
  1702.  
  1703. 	of<<"++iter测试:"<<endl;
  1704.  
  1705. 	for(;i<NUM1;++i)
  1706.  
  1707. 	{
  1708.  
  1709. 		iter = ls.begin();
  1710.  
  1711. 		dw1 = ::GetTickCount();
  1712.  
  1713. 		while (iter!=ls.end())
  1714.  
  1715. 		{
  1716.  
  1717. 			++iter;
  1718.  
  1719. 		}
  1720.  
  1721. 		dw2 = ::GetTickCount();
  1722.  
  1723. 		cout<<i<<" : "<<dw2-dw1<<endl;
  1724.  
  1725. 		of<<i<<" : "<<dw2-dw1<<endl;
  1726.  
  1727. 		total+=dw2-dw1;
  1728.  
  1729. 	}
  1730.  
  1731. 	cout<<"总消耗:"<<total<<endl;
  1732.  
  1733. 	of<<"总消耗:"<<total<<endl;
  1734.  
  1735. 	cout<<"平均消耗:"<<float(total)/NUM1<<endl;
  1736.  
  1737. 	of<<"平均消耗:"<<float(total)/NUM1<<endl;
  1738.  
  1739. 	cout<<endl;
  1740.  
  1741. 	of<<endl;
  1742.  
  1743. 	i=0;
  1744.  
  1745. 	total=0;
  1746.  
  1747. 	cout<<"citer++测试:"<<endl;
  1748.  
  1749. 	of<<"citer++测试:"<<endl;
  1750.  
  1751. 	for(;i<NUM1;++i)
  1752.  
  1753. 	{
  1754.  
  1755. 		citer = ls.begin();
  1756.  
  1757. 		dw1 = ::GetTickCount();
  1758.  
  1759. 		while (citer!=ls.end())
  1760.  
  1761. 		{
  1762.  
  1763. 			citer++;
  1764.  
  1765. 		}
  1766.  
  1767. 		dw2 = ::GetTickCount();
  1768.  
  1769. 		cout<<i<<" : "<<dw2-dw1<<endl;
  1770.  
  1771. 		of<<i<<" : "<<dw2-dw1<<endl;
  1772.  
  1773. 		total+=dw2-dw1;
  1774.  
  1775. 	}
  1776.  
  1777. 	cout<<"总消耗:"<<total<<endl;
  1778.  
  1779. 	of<<"总消耗:"<<total<<endl;
  1780.  
  1781. 	cout<<"平均消耗:"<<float(total)/NUM1<<endl;
  1782.  
  1783. 	of<<"平均消耗:"<<float(total)/NUM1<<endl;
  1784.  
  1785. 	cout<<endl;
  1786.  
  1787. 	of<<endl;
  1788.  
  1789. 	i=0;
  1790.  
  1791. 	total=0;
  1792.  
  1793. 	cout<<"++citer测试:"<<endl;
  1794.  
  1795. 	of<<"++citer测试:"<<endl;
  1796.  
  1797. 	for(;i<NUM1;++i)
  1798.  
  1799. 	{
  1800.  
  1801. 		citer = ls.begin();
  1802.  
  1803. 		dw1 = ::GetTickCount();
  1804.  
  1805. 		while (citer!=ls.end())
  1806.  
  1807. 		{
  1808.  
  1809. 			++citer;
  1810.  
  1811. 		}
  1812.  
  1813. 		dw2 = ::GetTickCount();
  1814.  
  1815. 		cout<<i<<" : "<<dw2-dw1<<endl;
  1816.  
  1817. 		of<<i<<" : "<<dw2-dw1<<endl;
  1818.  
  1819. 		total+=dw2-dw1;
  1820.  
  1821. 	}
  1822.  
  1823. 	cout<<"总消耗:"<<total<<endl;
  1824.  
  1825. 	of<<"总消耗:"<<total<<endl;
  1826.  
  1827. 	cout<<"平均消耗:"<<float(total)/NUM1<<endl;
  1828.  
  1829. 	of<<"平均消耗:"<<float(total)/NUM1<<endl;
  1830.  
  1831. 	cout<<endl;
  1832.  
  1833. 	of<<endl;
  1834.  
  1835. }
  1836.  
  1837. void test5_map_type2(ofstream &of)
  1838.  
  1839. {
  1840.  
  1841. 	map<int,ElemType2> ls;
  1842.  
  1843. 	char sz[255];
  1844.  
  1845. 	for (int n=0;n<NUM3;++n)
  1846.  
  1847. 	{
  1848.  
  1849. 		itoa(n,sz,10);
  1850.  
  1851. 		ls.insert(pair<int,ElemType2>(n,ElemType2(sz)));
  1852.  
  1853. 	}
  1854.  
  1855. 	DWORD dw1,dw2,total=0;
  1856.  
  1857. 	cout<<"map,使用type2:"<<endl;
  1858.  
  1859. 	of<<"map,使用type2:"<<endl;
  1860.  
  1861. 	cout<<"iter++测试:"<<endl;
  1862.  
  1863. 	of<<"iter++测试:"<<endl;
  1864.  
  1865. 	int i = 0,j=0;
  1866.  
  1867. 	map<int,ElemType2>::iterator iter;
  1868.  
  1869. 	map<int,ElemType2>::const_iterator citer;
  1870.  
  1871. 	for(;i<NUM1;++i)
  1872.  
  1873. 	{
  1874.  
  1875. 		iter = ls.begin();
  1876.  
  1877. 		dw1 = ::GetTickCount();
  1878.  
  1879. 		while (iter!=ls.end())
  1880.  
  1881. 		{
  1882.  
  1883. 			iter++;
  1884.  
  1885. 		}
  1886.  
  1887. 		dw2 = ::GetTickCount();
  1888.  
  1889. 		cout<<i<<" : "<<dw2-dw1<<endl;
  1890.  
  1891. 		of<<i<<" : "<<dw2-dw1<<endl;
  1892.  
  1893. 		total+=dw2-dw1;
  1894.  
  1895. 	}
  1896.  
  1897. 	cout<<"总消耗:"<<total<<endl;
  1898.  
  1899. 	of<<"总消耗:"<<total<<endl;
  1900.  
  1901. 	cout<<"平均消耗:"<<float(total)/NUM1<<endl;
  1902.  
  1903. 	of<<"平均消耗:"<<float(total)/NUM1<<endl;
  1904.  
  1905. 	cout<<endl;
  1906.  
  1907. 	of<<endl;
  1908.  
  1909. 	i=0;
  1910.  
  1911. 	total=0;
  1912.  
  1913. 	cout<<"++iter测试:"<<endl;
  1914.  
  1915. 	of<<"++iter测试:"<<endl;
  1916.  
  1917. 	for(;i<NUM1;++i)
  1918.  
  1919. 	{
  1920.  
  1921. 		iter = ls.begin();
  1922.  
  1923. 		dw1 = ::GetTickCount();
  1924.  
  1925. 		while (iter!=ls.end())
  1926.  
  1927. 		{
  1928.  
  1929. 			++iter;
  1930.  
  1931. 		}
  1932.  
  1933. 		dw2 = ::GetTickCount();
  1934.  
  1935. 		cout<<i<<" : "<<dw2-dw1<<endl;
  1936.  
  1937. 		of<<i<<" : "<<dw2-dw1<<endl;
  1938.  
  1939. 		total+=dw2-dw1;
  1940.  
  1941. 	}
  1942.  
  1943. 	cout<<"总消耗:"<<total<<endl;
  1944.  
  1945. 	of<<"总消耗:"<<total<<endl;
  1946.  
  1947. 	cout<<"平均消耗:"<<float(total)/NUM1<<endl;
  1948.  
  1949. 	of<<"平均消耗:"<<float(total)/NUM1<<endl;
  1950.  
  1951. 	cout<<endl;
  1952.  
  1953. 	of<<endl;
  1954.  
  1955. 	i=0;
  1956.  
  1957. 	total=0;
  1958.  
  1959. 	cout<<"citer++测试:"<<endl;
  1960.  
  1961. 	of<<"citer++测试:"<<endl;
  1962.  
  1963. 	for(;i<NUM1;++i)
  1964.  
  1965. 	{
  1966.  
  1967. 		citer = ls.begin();
  1968.  
  1969. 		dw1 = ::GetTickCount();
  1970.  
  1971. 		while (citer!=ls.end())
  1972.  
  1973. 		{
  1974.  
  1975. 			citer++;
  1976.  
  1977. 		}
  1978.  
  1979. 		dw2 = ::GetTickCount();
  1980.  
  1981. 		cout<<i<<" : "<<dw2-dw1<<endl;
  1982.  
  1983. 		of<<i<<" : "<<dw2-dw1<<endl;
  1984.  
  1985. 		total+=dw2-dw1;
  1986.  
  1987. 	}
  1988.  
  1989. 	cout<<"总消耗:"<<total<<endl;
  1990.  
  1991. 	of<<"总消耗:"<<total<<endl;
  1992.  
  1993. 	cout<<"平均消耗:"<<float(total)/NUM1<<endl;
  1994.  
  1995. 	of<<"平均消耗:"<<float(total)/NUM1<<endl;
  1996.  
  1997. 	cout<<endl;
  1998.  
  1999. 	of<<endl;
  2000.  
  2001. 	i=0;
  2002.  
  2003. 	total=0;
  2004.  
  2005. 	cout<<"++citer测试:"<<endl;
  2006.  
  2007. 	of<<"++citer测试:"<<endl;
  2008.  
  2009. 	for(;i<NUM1;++i)
  2010.  
  2011. 	{
  2012.  
  2013. 		citer = ls.begin();
  2014.  
  2015. 		dw1 = ::GetTickCount();
  2016.  
  2017. 		while (citer!=ls.end())
  2018.  
  2019. 		{
  2020.  
  2021. 			++citer;
  2022.  
  2023. 		}
  2024.  
  2025. 		dw2 = ::GetTickCount();
  2026.  
  2027. 		cout<<i<<" : "<<dw2-dw1<<endl;
  2028.  
  2029. 		of<<i<<" : "<<dw2-dw1<<endl;
  2030.  
  2031. 		total+=dw2-dw1;
  2032.  
  2033. 	}
  2034.  
  2035. 	cout<<"总消耗:"<<total<<endl;
  2036.  
  2037. 	of<<"总消耗:"<<total<<endl;
  2038.  
  2039. 	cout<<"平均消耗:"<<float(total)/NUM1<<endl;
  2040.  
  2041. 	of<<"平均消耗:"<<float(total)/NUM1<<endl;
  2042.  
  2043. 	cout<<endl;
  2044.  
  2045. 	of<<endl;
  2046.  
  2047. }
  2048.  
  2049. #define LOGFILE_PATH_A L"qin_nkl_23529303.etl"
  2050.  
  2051. int main()
  2052.  
  2053. {
  2054.  
  2055. 	string strFileName = _FNAME;
  2056.  
  2057. 	string strTime = __TIME__;
  2058.  
  2059. 	for(int k=0;k<strTime.length();++k)
  2060.  
  2061. 		if(strTime[k]==':')
  2062.  
  2063. 			strTime[k]='-';
  2064.  
  2065. 	strFileName+=strTime;
  2066.  
  2067. 	strFileName+="_test1.txt";
  2068.  
  2069. 	//文件测试用
  2070.  
  2071. 	char sz[MAX_PATH];
  2072.  
  2073. 	sprintf(sz,"F:\\parse_%s_%d.txt",LOGFILE_PATH_A,GetTickCount());
  2074.  
  2075. 	cout<<sz<<endl;
  2076.  
  2077. 	sprintf(sz,"F:\\parse_%S_%d.txt",LOGFILE_PATH_A,GetTickCount());
  2078.  
  2079. 	cout<<sz<<endl;
  2080.  
  2081. 	cin.get();
  2082.  
  2083. 	return 0;
  2084.  
  2085. 	//strFileName = sz;
  2086.  
  2087. 	ofstream of(strFileName.c_str());
  2088.  
  2089. 	of<<GetTickCount()<<endl;
  2090.  
  2091. 	of.flush();
  2092.  
  2093. 	of.close();
  2094.  
  2095. 	cin.get();
  2096.  
  2097. 	return 0;
  2098.  
  2099. 	test1_int_i(of);
  2100.  
  2101. 	test1_dword_i(of);
  2102.  
  2103. 	test2_vec_type1(of);
  2104.  
  2105. 	test2_vec_type2(of);
  2106.  
  2107. 	test3_list_type1(of);
  2108.  
  2109. 	test3_list_type2(of);
  2110.  
  2111. 	test4_set_type1(of);
  2112.  
  2113. 	test4_set_type2(of);
  2114.  
  2115. 	test5_map_type1(of);
  2116.  
  2117. 	test5_map_type2(of);
  2118.  
  2119. 	cout<<"标记:"<<g_dwFlag<<endl;
  2120.  
  2121. 	of.flush();
  2122.  
  2123. 	of.close();
  2124.  
  2125. 	cin.get();
  2126.  
  2127. 	return 0;
  2128.  
  2129. }
  2130.  

vector/list/set/map 遍历耗时统计的更多相关文章

  1. map遍历的四种方式

    原文 http://blog.csdn.net/dayanxuqun/article/details/26348277 以下是map遍历的四种方式: // 一.推荐只用value的时候用,都懂的... ...

  2. java map遍历方式及效率

    本文转载自Java Map遍历方式的选择. 只给出遍历方式及结论.测试数据可以去原文看. 如果你使用HashMap 同时遍历key和value时,keySet与entrySet方法的性能差异取决于ke ...

  3. 分页查询和分页缓存查询,List<Map<String, Object>>遍历和Map遍历

    分页查询 String sql = "返回所有符合条件记录的待分页SQL语句"; int start = (page - 1) * limit + 1; int end = pag ...

  4. springMVC Aspect AOP 接口耗时统计

    在接口开发中,我们通常需要统计接口耗时,为后续接口性能做统计.在springMVC中可以用它的aop来记录日志. 1.在spring配置文件中开启AOP <!--*************** ...

  5. js中三个对数组操作的函数 indexOf()方法 filter筛选 forEach遍历 map遍历

     indexOf()方法  indexOf()方法返回在该数组中第一个找到的元素位置,如果它不存在则返回-1. 不使用indexOf时 var arr = ['apple','orange','pea ...

  6. 原生JS forEach()和map()遍历的区别以及兼容写法

    一.原生JS forEach()和map()遍历 共同点: 1.都是循环遍历数组中的每一项. 2.forEach() 和 map() 里面每一次执行匿名函数都支持3个参数:数组中的当前项item,当前 ...

  7. map遍历性能记录

    map遍历可以通过keySet或者entrySet方式. 性能上:entrySet略胜一筹,原因是keySet获取到key后再根据key去获取value,在查一遍,所以慢一些. keySet: //先 ...

  8. forEach() 和 map() 遍历

    1.forEach()   没有返回值. arr[].forEach(function(value,index,array){ //do something }) 参数:value数组中的当前项, i ...

  9. js的map遍历和array遍历

    1. array遍历: [1].forEach() forEach是ES5中操作数组的一种方法,主要功能是遍历数组.forEach方法中的function回调有三个参数:第一个参数是遍历的数组内容,第 ...

随机推荐

  1. json语法和使用

    一.JSON 概述: JavaScript Object Natation,是一种轻量级的数据交换技术规范. 二.使用流程: 在服务端将java对象转换为JSON,然后发送到浏览器,在浏览器上在讲JS ...

  2. HDU6312 Game(博弈,拿出本数与这个数的除数)

    题意:A和B玩游戏 , 给出1 ~ n 的集合 ,每个人可以拿出一个数 , 这个数的除数也被拿出 , A先开始 , 没有数拿的人就输 , 问A赢不赢 分析:很有意思的一道题目 ///假设2 ~ n A ...

  3. v-model 用在组件中

    官方文档: 使用自定义事件的表单输入组件 官方也说明了,v-model只不过是一个语法糖而已,真正的实现靠的还是 1. v-bind : 绑定响应式数据 2. 触发 input 事件 并传递数据 (核 ...

  4. Oracle子分区(sub partition)操作

    要重新定义大量分区表. 首先看 SQL Reference 大致了解了 Oracle 的分区修改操作.Alter table 语句的alter_table_partitioning 子句可以分为以下几 ...

  5. linux 工具(1)------终端提示符配置

    Linux环境变量,PS1用于设置终端的提示符. 设置规则 设置方法 设置规则 \d :代表日期,格式为 Weekday Month Date,例如 "Mon Aug 1" \H ...

  6. elasticsearch fitler查询例子

  7. 存储型xss调研

    概念 存储型XSS,持久化,代码是存储在服务器中的,如在个人信息或发表文章等地方,加入代码,如果没有过滤或过滤不严,那么这些代码将储存到服务器中,用户访问该页面的时候触发代码执行. 常见的xss攻击方 ...

  8. [转] 微信小程序 页面跳转 传递参数

    本文转自:http://blog.csdn.net/qq_31383345/article/details/52795212 微信小程序的页面跳转,页面之间传递参数笔记. CSDN微信小程序开发专栏, ...

  9. [转]ASP.NET MVC中的两个Action之间值的传递--TempData

    本文转自:ASP.NET MVC中的两个Action之间值的传递--TempData 一. ASP.NET MVC中的TempData 在ASP.NET MVC框架的ControllerBase中存在 ...

  10. 1个示例 学会 mvc 常用标签

    HtmlHelper用法大全3:Html.LabelFor.Html.EditorFor.Html.RadioButtonFor.Html.CheckBoxFor  @Html.***For:为由指定 ...