level 11
endrollex
楼主
测试代码:
#include <iostream>
#include <vector>
#include <deque>
#include <ctime>
using namespace std;
int main()
{
vector<char> vc1(1000000000, 1);
//test1
//for (vector<char>::size_type ix = 0; ix != vc1.size(); ++ix) vc1[ix] += 1;
//test2
for (vector<char>::iterator it = vc1.begin(); it != vc1.end(); ++it) *it += 1;
cout << "----" << endl;
int tc1 = clock();
cout << "spend time: " << (float)tc1/CLOCKS_PER_SEC << " seconds" << endl;
return 0;
}
用下标花费13秒左右,
而用迭代器花费53秒左右
测试有问题吗?
2012年10月30日 07点10分
1
#include <iostream>
#include <vector>
#include <deque>
#include <ctime>
using namespace std;
int main()
{
vector<char> vc1(1000000000, 1);
//test1
//for (vector<char>::size_type ix = 0; ix != vc1.size(); ++ix) vc1[ix] += 1;
//test2
for (vector<char>::iterator it = vc1.begin(); it != vc1.end(); ++it) *it += 1;
cout << "----" << endl;
int tc1 = clock();
cout << "spend time: " << (float)tc1/CLOCKS_PER_SEC << " seconds" << endl;
return 0;
}
用下标花费13秒左右,
而用迭代器花费53秒左右
测试有问题吗?