fork(3) download
  1. #include <chrono>
  2. #include <sstream>
  3. #include <iostream>
  4.  
  5. int main()
  6. {
  7. using namespace std;
  8. using namespace chrono;
  9.  
  10. auto const loops_count{1000000};
  11. auto const p1{high_resolution_clock::now()};
  12. {
  13. stringstream ss;
  14. for(auto i{loops_count}; 0 != i; i--)
  15. {
  16. ss.str(string()); // clear
  17. ss << 1;
  18. }
  19. }
  20. auto const p2{high_resolution_clock::now()};
  21. {
  22. for(auto i{loops_count}; 0 != i; i--)
  23. {
  24. stringstream ss; // recreate
  25. ss << 1;
  26. }
  27. }
  28. auto const p3{high_resolution_clock::now()};
  29. cout << duration_cast< milliseconds >(p2 - p1).count() << "ms "
  30. << duration_cast< milliseconds >(p3 - p2).count() << "ms"
  31. << endl;
  32.  
  33. return 0;
  34. }
  35.  
Success #stdin #stdout 0.46s 16064KB
stdin
Standard input is empty
stdout
35ms 431ms