Hello,
This code with bzip2 takes 185 seconds to do 10000 iterations of compressing
and uncompressing. This seems way too high. When I replace the bzip2 code
with zlib code it take roughly 7 seconds. Anyone know what might be wrong?
#include <iostream>
#include <sstream>
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
typedef boost::posix_time::ptime TimeType;
TimeType current_time()
{
return boost::posix_time::microsec_clock::local_time();
}
double elapsed_seconds(const TimeType& start_time)
{
static const double MSEC_PER_SEC = 1000.0;
TimeType end_time = current_time();
boost::posix_time::time_duration elapsed = end_time - start_time;
return boost::numeric_cast<double>(elapsed.total_milliseconds()) /
MSEC_PER_SEC;
}
string decompress(const string& data)
{
boost::iostreams::filtering_streambufboost::iostreams::input in;
in.push(boost::iostreams::bzip2_decompressor());
in.push(boost::make_iterator_range(data));
string decompressed;
boost::iostreams::copy(in,
boost::iostreams::back_inserter(decompressed));
return decompressed;
}
int main()
{
TimeType start_time = current_time();
string compressed, received_data;
boost::iostreams::filtering_streambufboost::iostreams::output out, in;
const string send_data = "boo! how are you?";
for(int i = 0; i < 10000; ++i)
{
//compress
out.push(boost::iostreams::bzip2_compressor());
out.push(boost::iostreams::back_inserter(compressed));
boost::iostreams::copy(boost::make_iterator_range(send_data), out);
const string compressed1=compressed;
//decompress
received_data = decompress(compressed);
}
cout << "time elapsed: " << elapsed_seconds(start_time) << endl;
}
--
View this message in context: http://www.nabble.com/why-is-this-bzip2-boost-code-so-slow--tp25442062p25442...
Sent from the Boost - Users mailing list archive at Nabble.com.