Advertisement
eXFq7GJ1cC

Untitled

Jul 26th, 2012
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.90 KB | None | 0 0
  1. #include <list>
  2. #include <vector>
  3. #include <iostream>
  4. #include <chrono>
  5. #include <cstdlib>
  6. #include <cmath>
  7. using namespace std;
  8. using namespace std::chrono;
  9.  
  10. int main(int argc, char **argv)
  11. {
  12.     size_t N = pow(10, atoi(argv[1]));
  13.     cout << "  size: " << N << endl;
  14.  
  15.     {
  16.         vector<int> v;
  17.         auto start = high_resolution_clock::now();
  18.         for(size_t i = 0; i < N; i++)
  19.             v.push_back(42);
  20.         auto end = high_resolution_clock::now();
  21.         cout << "vector: " << duration_cast<microseconds>(end - start).count() << " us" << endl;
  22.     }
  23.  
  24.     {
  25.         list<int> l;
  26.         auto start = high_resolution_clock::now();
  27.         for(size_t i = 0; i < N; i++)
  28.             l.push_back(42);
  29.         auto end = high_resolution_clock::now();
  30.         cout << "  list: " << duration_cast<microseconds>(end - start).count() << " us" << endl;
  31.     }
  32.     cout << endl;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement