[英]boost::iostreams::::copy Seems Excessively Slow
I am using boost::iostreams::::copy
in it's common role of as part compressing a stream in memory. 我正在使用boost::iostreams::::copy
,这是压缩内存中流的一部分。 However, it seems excessively slow when copying a rather large compressed stream: ~30 MB may take ~2 minutes. 但是,复制相当大的压缩流时,它似乎过慢:〜30 MB可能需要约2分钟。
Here is my code: 这是我的代码:
std::stringstream compress(std::stringstream& data)
{
namespace bio = boost::iostreams;
std::stringstream comp;
bio::filtering_streambuf<bio::input> out;
out.push(bio::gzip_compressor(bio::gzip_params(bio::gzip::best_compression)));
out.push(data);
bio::copy(out, comp);
return comp;
}
The culprit is the line: 罪魁祸首是这行:
bio::copy(out, comp);
The data is in bytes and contains NULs if that matters but I need to use std::stringstream
. 数据以字节为单位,如果很重要,则包含NUL,但我需要使用std::stringstream
。
Does anyone see an issue with my code or have suggestions on what may improve my code? 是否有人看到我的代码有问题或对改进我的代码有建议? Perhaps it just takes that long though it seems excessive. 也许花了很长时间,尽管看起来似乎过多。
In a stunning- no, jaw-dropping- turn of events, it seems bio::gzip::best_compression
is the real culprit. 在令人惊叹的,绝不令人bio::gzip::best_compression
的事件中,似乎bio::gzip::best_compression
是真正的罪魁祸首。
When I changed it to bio::gzip::best_speed
, I got these (rough) results: 当我将其更改为bio::gzip::best_speed
,我得到了以下(大致)结果:
bio::gzip::best_compression: output size 6589968 bytes elapsed time: 105881 ms
bio::gzip::best_speed: output size: 6589596 bytes elapsed time: 6065 ms
So it seems in my case (without regard to exactly why- probably the nature of the data) the answer is to change compression level. 因此,在我的情况下(不考虑确切原因-可能是数据的性质),答案似乎是更改压缩级别。
Note: That's with VC++ 2017 in debug. 注意:调试时使用VC ++ 2017。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.