I am using a function which needs content from zipped xml file. The signature of the function is
endgoalFn(const char* s, int len)
Below is the code i use for unzipping
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);
Below code i use for copying the content to a string and provide it to endgoal fn
std::stringstream buffer;
boost::iostreams::copy(in, buffer);
std::string content(std::move(buffer.str()));
endgoalFn(&content[0], content.size());
The three lines before calling endgoalFn takes x amount of ms depending on the size of the zipped file.
Is there any alternate way i can get the input for first argument in endgoalFn from filtering_streambuf so that i can decrease x amount of ms by few ms?
Update
it was suggested in comments to measure using optimized build.
example code contains two ways (original and the one suggested by @sehe)
2.4M resultFile
Consuming 7975424 bytes
withSStream, time taken: 136ms
Consuming 7975424 bytes
withoutSStream, time taken: 160ms
As others have noted, make sure you measure in Release build configuration.
Besides, there is no need to move to a string stream first:
Now you can directly
More Ideas
If XML files can be large, and if
endgoalFncan handle partial input (e.g. you can call it in a loop) you can do a buffered read:UPDATE - Live Demo
See both demonstrated with a slightly modified sample that is self-contained:
Live On Coliru
Compiled for STREAMING:
Prints e.g.