fork(1) download
  1. #include <iostream>
  2. #include <chrono>
  3. #include <cmath>
  4. using namespace std;
  5. using std::chrono::high_resolution_clock;
  6. using std::chrono::nanoseconds;
  7. using std::chrono::duration_cast;
  8.  
  9. inline int size() {
  10. return 1000;
  11. }
  12.  
  13. double shit = 0.2;
  14. void do_work() {
  15. shit += sin(shit);
  16. }
  17.  
  18. int main() {
  19. auto t1 = high_resolution_clock::now();
  20. for ( int i=size(); i--; ) do_work();
  21. auto t2 = high_resolution_clock::now();
  22. for ( int i = 0; i < size(); ++i ) do_work();
  23. auto t3 = high_resolution_clock::now();
  24. auto timer1 = duration_cast<nanoseconds>(t2 - t1).count();
  25. auto timer2 = duration_cast<nanoseconds>(t3 - t2).count();
  26. cout << timer1 << ", " << timer2 << ", " << shit;
  27. return 0;
  28. }
Success #stdin #stdout 0s 3140KB
stdin
Standard input is empty
stdout
805305, 800440, 3.14159