diff options
author | Yann Collet <cyan@fb.com> | 2017-09-07 19:12:36 (GMT) |
---|---|---|
committer | Yann Collet <cyan@fb.com> | 2017-09-07 19:12:36 (GMT) |
commit | 00418f76115e3c435b4cb0e41b30fba8e8e3adee (patch) | |
tree | be170cefe4819f5d7ac93e725aa65f7742aebbda /examples/blockStreaming_ringBuffer.c | |
parent | ee5332438b9a4c65147003334bcdbb9915930603 (diff) | |
download | lz4-00418f76115e3c435b4cb0e41b30fba8e8e3adee.zip lz4-00418f76115e3c435b4cb0e41b30fba8e8e3adee.tar.gz lz4-00418f76115e3c435b4cb0e41b30fba8e8e3adee.tar.bz2 |
bench : made decompression speed evaluation same time as compression
minor : slightly modified an example do avoid disabling a gcc warning through #pragma
Diffstat (limited to 'examples/blockStreaming_ringBuffer.c')
-rw-r--r-- | examples/blockStreaming_ringBuffer.c | 45 |
1 files changed, 17 insertions, 28 deletions
diff --git a/examples/blockStreaming_ringBuffer.c b/examples/blockStreaming_ringBuffer.c index 697d342..40109b5 100644 --- a/examples/blockStreaming_ringBuffer.c +++ b/examples/blockStreaming_ringBuffer.c @@ -1,5 +1,5 @@ -// LZ4 streaming API example : ring buffer -// Based on sample code from Takayuki Matsuoka +/* LZ4 streaming API example : ring buffer + * Based on sample code from Takayuki Matsuoka */ /************************************** @@ -9,9 +9,6 @@ # define _CRT_SECURE_NO_WARNINGS // for MSVC # define snprintf sprintf_s #endif -#ifdef __GNUC__ -# pragma GCC diagnostic ignored "-Wmissing-braces" /* GCC bug 53119 : doesn't accept { 0 } as initializer (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53119) */ -#endif /************************************** @@ -50,7 +47,7 @@ size_t read_bin(FILE* fp, void* array, int arrayBytes) { void test_compress(FILE* outFp, FILE* inpFp) { - LZ4_stream_t lz4Stream_body = { 0 }; + LZ4_stream_t lz4Stream_body = { { 0 } }; LZ4_stream_t* lz4Stream = &lz4Stream_body; static char inpBuf[RING_BUFFER_BYTES]; @@ -85,24 +82,22 @@ void test_compress(FILE* outFp, FILE* inpFp) void test_decompress(FILE* outFp, FILE* inpFp) { static char decBuf[DECODE_RING_BUFFER]; - int decOffset = 0; - LZ4_streamDecode_t lz4StreamDecode_body = { 0 }; + int decOffset = 0; + LZ4_streamDecode_t lz4StreamDecode_body = { { 0 } }; LZ4_streamDecode_t* lz4StreamDecode = &lz4StreamDecode_body; for(;;) { int cmpBytes = 0; char cmpBuf[CMPBUFSIZE]; - { - const size_t r0 = read_int32(inpFp, &cmpBytes); + { const size_t r0 = read_int32(inpFp, &cmpBytes); if(r0 != 1 || cmpBytes <= 0) break; const size_t r1 = read_bin(inpFp, cmpBuf, cmpBytes); if(r1 != (size_t) cmpBytes) break; } - { - char* const decPtr = &decBuf[decOffset]; + { char* const decPtr = &decBuf[decOffset]; const int decBytes = LZ4_decompress_safe_continue( lz4StreamDecode, cmpBuf, decPtr, cmpBytes, MESSAGE_MAX_BYTES); if(decBytes <= 0) break; @@ -120,7 +115,7 @@ int compare(FILE* f0, FILE* f1) { int result = 0; - while(0 == result) { + while (0 == result) { char b0[65536]; char b1[65536]; const size_t r0 = fread(b0, 1, sizeof(b0), f0); @@ -128,12 +123,9 @@ int compare(FILE* f0, FILE* f1) result = (int) r0 - (int) r1; - if(0 == r0 || 0 == r1) { - break; - } - if(0 == result) { - result = memcmp(b0, b1, r0); - } + if (0 == r0 || 0 == r1) break; + + if (0 == result) result = memcmp(b0, b1, r0); } return result; @@ -160,9 +152,8 @@ int main(int argc, char** argv) printf("dec = [%s]\n", decFilename); // compress - { - FILE* inpFp = fopen(inpFilename, "rb"); - FILE* outFp = fopen(lz4Filename, "wb"); + { FILE* const inpFp = fopen(inpFilename, "rb"); + FILE* const outFp = fopen(lz4Filename, "wb"); test_compress(outFp, inpFp); @@ -171,9 +162,8 @@ int main(int argc, char** argv) } // decompress - { - FILE* inpFp = fopen(lz4Filename, "rb"); - FILE* outFp = fopen(decFilename, "wb"); + { FILE* const inpFp = fopen(lz4Filename, "rb"); + FILE* const outFp = fopen(decFilename, "wb"); test_decompress(outFp, inpFp); @@ -182,9 +172,8 @@ int main(int argc, char** argv) } // verify - { - FILE* inpFp = fopen(inpFilename, "rb"); - FILE* decFp = fopen(decFilename, "rb"); + { FILE* const inpFp = fopen(inpFilename, "rb"); + FILE* const decFp = fopen(decFilename, "rb"); const int cmp = compare(inpFp, decFp); if(0 == cmp) { |