fork(1) download
  1. #include <iostream>
  2. #include <vector>
  3. #include <ctime>
  4. using namespace std;
  5.  
  6. int main() {
  7. const int N = 10000000;
  8.  
  9. clock_t tStart;
  10.  
  11. vector<int> a;
  12.  
  13. tStart = clock();
  14. for(int i=0; i<N; i++) a.push_back(i);
  15. printf("Time taken: %.4f sec\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
  16.  
  17. vector<int> b;
  18.  
  19. tStart = clock();
  20. for(int i=0; i<N; i++) {
  21. b.resize(i+1);
  22. b[i] = i;
  23. // b.push_back(i);
  24. }
  25. printf("Time taken: %.4f sec\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
  26.  
  27. return 0;
  28. }
  29.  
Success #stdin #stdout 0.13s 49480KB
stdin
Standard input is empty
stdout
Time taken: 0.0659 sec
Time taken: 0.0681 sec