Advertisement
bolverk

map vector flat map benchmark

Sep 1st, 2015
317
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.71 KB | None | 0 0
  1. #include <ctime>
  2. #include <iostream>
  3. #include <vector>
  4. #include <algorithm>
  5. #include <stack>
  6. #include <map>
  7. #include "boost/container/flat_map.hpp"
  8.  
  9. using namespace std;
  10.  
  11. namespace {
  12.  
  13.   template <class S> void time_copy_test(size_t np, const S& s)
  14.   {
  15.     const clock_t start = clock();
  16.     for(size_t i=0;i<np;++i)
  17.       S temp = s;
  18.     cout << static_cast<double>(clock()-start)/CLOCKS_PER_SEC << endl;
  19.   }
  20. }
  21.  
  22. int main(void)
  23. {
  24.     const size_t np = 100000000;
  25.     cout << "stl map: ";
  26.     time_copy_test(np,std::map<size_t,double>());
  27.     cout << "stl vector: ";
  28.     time_copy_test(np,vector<double>());
  29.     cout << "boost flat map: ";
  30.     time_copy_test(np,boost::container::flat_map<size_t,double>());
  31.     return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement