从GZIP压缩文件高效获取字符传入endgoalFn的优化问询
直接从解压流传递数据给目标函数以减少耗时?
目标函数签名
endgoalFn(const char* s, int len)
现有解压实现
std::ifstream file; file.open(resultFile, std::ios_base::in | std::ios_base::binary); boost::iostreams::filtering_streambuf<boost::iostreams::input> in; in.push(boost::iostreams::gzip_decompressor()); in.push(file);
当前传递内容的方式
将解压后的数据存入字符串再传入目标函数:
std::stringstream buffer; boost::iostreams::copy(in, buffer); std::string content(std::move(buffer.str())); endgoalFn(&content[0], content.size());
调用endgoalFn前的三行代码耗时x毫秒,时长与压缩文件大小正相关。
疑问
有没有办法直接从filtering_streambuf获取endgoalFn所需的const char*输入,从而减少这部分耗时?
更新测试结果
经优化构建版本测试,对比两种实现方式的耗时:
2.4M resultFile Consuming 7975424 bytes withSStream, time taken: 136ms Consuming 7975424 bytes withoutSStream, time taken: 160ms
内容的提问来源于stack exchange,提问作者nanika
相关产品推荐
相关产品推荐

