@
chendy #include <iostream>
#include <chrono>
#include <sstream>
int main() {
// Output the result
auto start_time = std::chrono::high_resolution_clock::now();
std::ios::sync_with_stdio(false);
std::cin.tie(NULL);
const size_t bufferSize = 1024 * 1024 * 100;
char *buffer = new char[bufferSize];
std::cout.rdbuf()->pubsetbuf(buffer, bufferSize);
std::ostringstream oss;
for (int i = -1; ++i < 1000; ) {
oss << "Column 1: 1, Column 2: 2, Column 3: 3, Column 4: 4\n";
}
std::cout << oss.str();
auto end_time = std::chrono::high_resolution_clock::now();
std::chrono::duration<double, std::milli> elapsed = end_time - start_time;
std::cout << "Time taken to output the result: " << elapsed.count() << " milliseconds\n";
delete[] buffer;
return 0;
}
编译 g++ main.cpp -O3
运行 a.exe
Time taken to output the result: 124.007 milliseconds
这是 c++ 写的代码 我已经将 buffer 调大了 但是还是维持在 100ms 左右