fork(1) download
  1.  
  2. #include <iostream>
  3. #include <vector>
  4. #include <string>
  5. #include <chrono>
  6. using namespace std;
  7.  
  8.  
  9. class MyObject {
  10. public:
  11. MyObject(string Str) : m_Str(Str) { }
  12.  
  13. string m_Str;
  14. };
  15.  
  16. int main() {
  17. chrono::time_point<chrono::system_clock> tstart, tend;
  18. chrono::duration<double> tt;
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25. tstart = chrono::system_clock::now();
  26.  
  27. vector<MyObject> VectorOfObjects;
  28. for (int i=0; i<10000; i++) {
  29. MyObject x("test");
  30. VectorOfObjects.push_back(x);
  31. }
  32.  
  33. tend = chrono::system_clock::now();
  34. tt = tend-tstart;
  35. cout << "Pushback Object: " << tt.count()*1000 << " Milliseconds\n" << endl;
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43. tstart = chrono::system_clock::now();
  44.  
  45. vector<MyObject *> VectorOfPointers;
  46. for (int i=0; i<10000; i++) {
  47. VectorOfPointers.push_back(new MyObject("test"));
  48. }
  49.  
  50. tend = chrono::system_clock::now();
  51. tt = tend-tstart;
  52. cout << "Pushback Pointers: " << tt.count()*1000 << " Milliseconds\n" << endl;
  53.  
  54.  
  55.  
  56. return 0;
  57. }
  58.  
  59.  
  60.  
Success #stdin #stdout 0s 4144KB
stdin
Standard input is empty
stdout
Pushback Object: 1.82652 Milliseconds

Pushback Pointers: 2.41375 Milliseconds