本文整理汇总了C++中Compressor::GetResultSize方法的典型用法代码示例。如果您正苦于以下问题:C++ Compressor::GetResultSize方法的具体用法?C++ Compressor::GetResultSize怎么用?C++ Compressor::GetResultSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Compressor
的用法示例。
在下文中一共展示了Compressor::GetResultSize方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CompressSimpleHelper
// CompressSimpleHelper
//------------------------------------------------------------------------------
void TestCompressor::CompressSimpleHelper( const char * data,
size_t size,
size_t expectedCompressedSize,
bool shouldCompress ) const
{
// raw input strings may not be aligned on Linux/OSX, so copy
// them to achieve our required alignment
char * alignedData = FNEW( char[ size ] );
memcpy( alignedData, data, size );
data = alignedData;
// compress
Compressor c;
const bool compressed = c.Compress( data, size );
TEST_ASSERT( compressed == shouldCompress );
const size_t compressedSize = c.GetResultSize();
if ( expectedCompressedSize > 0 )
{
TEST_ASSERT( compressedSize == expectedCompressedSize );
}
void const * compressedMem = c.GetResult();
// decompress
Compressor d;
d.Decompress( compressedMem );
const size_t decompressedSize = d.GetResultSize();
TEST_ASSERT( decompressedSize == size );
TEST_ASSERT( memcmp( data, d.GetResult(), size ) == 0 );
FDELETE_ARRAY( alignedData );
}
示例2: CompressHelper
// CompressHelper
//------------------------------------------------------------------------------
void TestCompressor::CompressHelper( const char * fileName ) const
{
// read some test data into a file
AutoPtr< void > data;
size_t dataSize;
{
FileStream fs;
TEST_ASSERT( fs.Open( fileName ) );
dataSize = (size_t)fs.GetFileSize();
data = (char *)ALLOC( dataSize );
TEST_ASSERT( (uint32_t)fs.Read( data.Get(), dataSize ) == dataSize );
}
OUTPUT( "File : %s\n", fileName );
OUTPUT( "Size : %u\n", (uint32_t)dataSize );
// compress the data to obtain size
Compressor comp;
comp.Compress( data.Get(), dataSize );
size_t compressedSize = comp.GetResultSize();
AutoPtr< char > compressedData( (char *)ALLOC( compressedSize ) );
memcpy( compressedData.Get(), comp.GetResult(), compressedSize );
float compressedPerc = ( (float)compressedSize / (float)dataSize ) * 100.0f;
OUTPUT( "Compressed Size: %u (%2.1f%% of original)\n", (uint32_t)compressedSize, compressedPerc );
// decompress to check we get original data back
Compressor decomp;
decomp.Decompress( compressedData.Get() );
size_t uncompressedSize = decomp.GetResultSize();
TEST_ASSERT( uncompressedSize == dataSize );
for ( size_t i=0; i<uncompressedSize; ++i )
{
TEST_ASSERT( ( (char *)data.Get() )[ i ] == ( (char *)decomp.GetResult() )[ i ] );
}
// speed checks
//--------------
const size_t NUM_REPEATS( 100 );
// compress the data several times to get more stable throughput value
Timer t;
for ( size_t i=0; i<NUM_REPEATS; ++i )
{
Compressor c;
c.Compress( data.Get(), dataSize );
TEST_ASSERT( c.GetResultSize() == compressedSize );
}
float compressTimeTaken = t.GetElapsed();
double compressThroughputMBs = ( ( (double)dataSize / 1024.0 * (double)NUM_REPEATS ) / compressTimeTaken ) / 1024.0;
OUTPUT( " Comp Speed: %2.1f MB/s - %2.3fs (%u repeats)\n", (float)compressThroughputMBs, compressTimeTaken, NUM_REPEATS );
// decompress the data
Timer t2;
for ( size_t i=0; i<NUM_REPEATS; ++i )
{
Compressor d;
d.Decompress( compressedData.Get() );
TEST_ASSERT( d.GetResultSize() == dataSize );
}
float decompressTimeTaken = t2.GetElapsed();
double decompressThroughputMBs = ( ( (double)dataSize / 1024.0 * (double)NUM_REPEATS ) / decompressTimeTaken ) / 1024.0;
OUTPUT( " Decomp Speed: %2.1f MB/s - %2.3fs (%u repeats)\n", (float)decompressThroughputMBs, decompressTimeTaken, NUM_REPEATS );
// time memcpy to compare with
Timer t0;
for ( size_t i=0; i<NUM_REPEATS; ++i )
{
char * mem = (char *)ALLOC( dataSize );
memcpy( mem, data.Get(), dataSize );
FREE( mem );
}
float memcpyTimeTaken = t0.GetElapsed();
double memcpyThroughputMBs = ( ( (double)dataSize / 1024.0 * (double)NUM_REPEATS ) / memcpyTimeTaken ) / 1024.0;
OUTPUT( " MemCpy Speed: %2.1f MB/s - %2.3fs (%u repeats)\n", (float)memcpyThroughputMBs, memcpyTimeTaken, NUM_REPEATS );
}