fork download
  1. #include <iostream>
  2. #include <chrono>
  3.  
  4. using namespace std;
  5.  
  6. const unsigned long long N = 1000000000ULL;
  7.  
  8. unsigned long long s(unsigned long long n)
  9. {
  10. unsigned long long s = 0;
  11.  
  12. for (unsigned long long i = 0; i < n; i++)
  13. s += i;
  14.  
  15. return s;
  16. }
  17.  
  18. int main()
  19. {
  20. auto t1 = std::chrono::high_resolution_clock::now();
  21.  
  22. auto x = s(N);
  23.  
  24. auto t2 = std::chrono::high_resolution_clock::now();
  25. auto t = std::chrono::duration_cast<std::chrono::nanoseconds>(t2 - t1).count();
  26.  
  27. cout << "Result: " << x << " -- time (ms):" << t/0.1e7 << endl;
  28. }
Success #stdin #stdout 1.31s 3340KB
stdin
Standard input is empty
stdout
Result: 499999999500000000 -- time (ms):1313.78