标签:
#include <iostream> #include <vector> #include <algorithm> #include <boost/timer.hpp> #define NUMS (10000000) int main() { std::vector<int> v1, v2; for(int i=0; i<NUMS; i++){ v1.push_back(1); } boost::timer t; double elapse; std::cout<<"max time elapsed can be tested = "<<t.elapsed_max()/3600<<"h"<<std::endl; std::cout<<"min time elapsed can be tested = "<<t.elapsed_min()<<"s"<<std::endl; v2.insert(v2.begin(), v1.begin(), v1.end()); elapse = t.elapsed(); std::cout<<"区间insert插入"<<NUMS<<"个数的时间 = "<<elapse<<std::endl; std::vector<int>().swap(v2); std::vector<int>::iterator tmp(v2.begin()); t.restart(); for(int i=0; i<NUMS; i++){ tmp = v2.insert(tmp, v1[i]); ++tmp; } elapse = t.elapsed(); std::cout<<"循环insert插入"<<NUMS<<"个数的时间 = "<<elapse<<std::endl; return 0; }
标签:
原文地址:http://my.oschina.net/u/2368952/blog/420646