问:有没有办法加快 clang++ STD 库 fstreams 的速度?(有人知道为什么它比 g++ 慢得多吗?)
我正在尝试处理非常大(许多 GB)的二进制数据文件,并惊讶地发现性能如此之差。起初,我认为这与我的代码有关。但是我在一个简化的示例中看到了同样缓慢的性能。
我什至尝试通过 rdbuf()->pubsetbuf() 分配不同大小的缓冲区,但这似乎没有太大效果。
这是一个简单的输入/输出示例:
#include <fstream>
int main() {
std::ifstream is {"bigSourceFile"};
std::ofstream os {"bigSourceFileCopy"};
std::string line;
while (std::getline (is, line) ) {
os << line;
}
}
Run Code Online (Sandbox Code Playgroud)
下面是一些生成 1.3GB 源文件的代码。使用它来生成 readWrite 程序的源文件:
#include <fstream>
#include <string>
std::string createTailStr () {
std::string result {"__"};
for (auto i (0); i< 58; ++i) {
result += 'A'+i;
}
return result;
}
int main() {
std::string tail {createTailStr()};
std::ofstream os {"bigSourceFile"};
constexpr auto …Run Code Online (Sandbox Code Playgroud)