1 #include <set> 2 #include <vector> 3 #include <iostream> 4 #include <boost/timer.hpp> 5 #include <boost/lexical_cast.hpp> 6 7 struct compare 8 { 9 bool operator()(int* x, int* y) 10 { return *x < *y; } 11 12 }; 13 14 int main(int argc, char const* const argv[]) 15 { 16 std::size_t niters = argc < 2 ? 1000 : boost::lexical_cast<std::size_t>(argv[1]); 17 18 boost::timer t; 19 20 std::vector<int> v; 21 for (int n = 0; n < niters; ++n) 22 { 23 v.insert(v.begin() + v.size()/2, n); 24 } 25 26 std::cout << "vector fill: " << t.elapsed() << std::endl; 27 28 std::multiset<int*,compare> m; 29 for (int n = 0; n < niters; ++n) 30 { 31 m.insert(&v[n]); 32 } 33 std::cout << "map fill 1: " << t.elapsed() << std::endl; 34 for (int n = 0; n < niters; ++n) 35 { 36 m.insert(&v[n]); 37 } 38 std::cout << "map fill 2: " << t.elapsed() << std::endl; 39 } 40