fork download
  1. #include <iostream>
  2. #include <chrono>
  3.  
  4. using namespace std;
  5.  
  6. double calc1(const int* a, const int* b) {
  7.  
  8. auto start = chrono::system_clock::now();
  9.  
  10. int* c = new int[10000000];
  11.  
  12. for (int i = 0; i < 10000000; i++)
  13. c[i] = a[i] + b[i];
  14.  
  15. delete[] c;
  16.  
  17. return chrono::duration<double>( chrono::system_clock::now() -start).count();
  18. }
  19.  
  20. double calc2(const int*a, const int*b) {
  21.  
  22. auto start = chrono::system_clock::now();
  23.  
  24. int* c = new int[10000000];
  25.  
  26. delete[] c;
  27.  
  28. return chrono::duration<double>(chrono::system_clock::now() - start).count();
  29.  
  30. }
  31.  
  32. int main() {
  33. // your code goes here
  34. int* a = new int[10000000];
  35. int* b = new int[10000000];
  36.  
  37. std::cout << calc1(a, b) << '\n' << calc2(a, b);
  38.  
  39. delete[] a;
  40. delete[] b;
  41. }
Success #stdin #stdout 0.02s 16064KB
stdin
Standard input is empty
stdout
0.0222257
1.0411e-05