RobertDeMilo

RB2.6 Производительность потоков вывода

Apr 15th, 2024
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.89 KB | None | 0 0
  1. // endl: 5035 ms
  2. // '\n' : 695 ms
  3.  
  4. // Использование endl может приводить к снижению скорости вывода в файл, cerr или cout
  5.  
  6. #include <iostream>
  7. #include <vector>
  8. #include <fstream>
  9.  
  10. #include "log_duration.h"
  11.  
  12. using namespace std;
  13.  
  14. int main()
  15. {
  16.     {
  17.         LOG_DURATION("endl");
  18.         ofstream out("output.txt");
  19.         for (int i = 0; i < 150'000; ++i)
  20.        {
  21.            out << "London is the capital of GreatBritain. "
  22.                << "I am travellong down the river"
  23.                << endl;
  24.        }
  25.    }
  26.  
  27.    {
  28.        LOG_DURATION("'\\n'");
  29.        ofstream out("output2.txt");
  30.        for (int i = 0; i < 150'000; ++i)
  31.         {
  32.             out << "London is the capital of GreatBritain. "
  33.                 << "I am travellong down the river"
  34.                 << '\n';
  35.         }
  36.     }
  37.    
  38. }
Advertisement
Add Comment
Please, Sign In to add comment