fork download
  1. #include <iostream>
  2. #include <chrono>
  3. #include <cmath>
  4.  
  5. using namespace std;
  6. using namespace chrono;
  7.  
  8. const int TIMES = 10000000;
  9.  
  10. int main() {
  11. auto start = system_clock::now();
  12. double s = 0.0;
  13. for(int i=0;i<TIMES;++i){
  14. double x = static_cast<double>(i);
  15. s += x*x*x;
  16. }
  17. cout<<s<<" counted by mult in "<< (duration_cast<milliseconds>(system_clock::now()-start).count())<<"ms"<<endl;
  18. start = system_clock::now();
  19. s = 0.0;
  20. for(int i=0;i<TIMES;++i){
  21. double x = static_cast<double>(i);
  22. s += pow(x,3);
  23. }
  24. cout<<s<<" counted by pow in "<< (duration_cast<milliseconds>(system_clock::now()-start).count())<<"ms"<<endl;
  25. return 0;
  26. }
Success #stdin #stdout 0.54s 15232KB
stdin
Standard input is empty
stdout
2.5e+27 counted by mult in 7ms
2.5e+27 counted by pow in 540ms