Skip to content

Commit 1bb1b2a

Browse files
committed
add slz4
1 parent 57549d5 commit 1bb1b2a

File tree

4 files changed

+5872
-192
lines changed

4 files changed

+5872
-192
lines changed

test/doc/LICENSE

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
xxHash Library
2+
Copyright (c) 2012-2020 Yann Collet
3+
All rights reserved.
4+
5+
BSD 2-Clause License (https://www.opensource.org/licenses/bsd-license.php)
6+
7+
Redistribution and use in source and binary forms, with or without modification,
8+
are permitted provided that the following conditions are met:
9+
10+
* Redistributions of source code must retain the above copyright notice, this
11+
list of conditions and the following disclaimer.
12+
13+
* Redistributions in binary form must reproduce the above copyright notice, this
14+
list of conditions and the following disclaimer in the documentation and/or
15+
other materials provided with the distribution.
16+
17+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
21+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
24+
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27+
28+
----------------------------------------------------
29+
30+
xxhsum command line interface
31+
Copyright (c) 2013-2020 Yann Collet
32+
All rights reserved.
33+
34+
GPL v2 License
35+
36+
This program is free software; you can redistribute it and/or modify
37+
it under the terms of the GNU General Public License as published by
38+
the Free Software Foundation; either version 2 of the License, or
39+
(at your option) any later version.
40+
41+
This program is distributed in the hope that it will be useful,
42+
but WITHOUT ANY WARRANTY; without even the implied warranty of
43+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
44+
GNU General Public License for more details.
45+
46+
You should have received a copy of the GNU General Public License along
47+
with this program; if not, write to the Free Software Foundation, Inc.,
48+
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

test/main.cpp

+42-4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@
1919
# include <lz4/lz4.h>
2020
#endif
2121

22+
#define USE_RC
23+
#define USE_ADAPTIVE
24+
#define USE_SLZ4
25+
#define USE_ZLIB
26+
27+
//#undef USE_LZ4
28+
2229
class Timer
2330
{
2431
public:
@@ -46,9 +53,11 @@ long long Timer::microseconds() const
4653
return std::chrono::duration_cast<std::chrono::microseconds>(end_ - start_).count();
4754
}
4855

56+
#ifdef USE_SLZ4
4957
int def_slz4(cpprcoder::MemoryStream& outStream, cpprcoder::u32 srcSize, cpprcoder::u8* src)
5058
{
51-
cpprcoder::s32 result = slz4::compress(outStream.capacity(), reinterpret_cast<slz4::u8*>(&outStream[0]), srcSize, reinterpret_cast<slz4::u8*>(src));
59+
slz4::SLZ4Context context;
60+
cpprcoder::s32 result = slz4::compress(context, outStream.capacity(), reinterpret_cast<slz4::u8*>(&outStream[0]), srcSize, reinterpret_cast<slz4::u8*>(src));
5261

5362
if(0 <= result) {
5463
outStream.resize(result);
@@ -64,7 +73,9 @@ int inf_slz4(cpprcoder::MemoryStream& outStream, cpprcoder::u32 srcSize, cpprcod
6473
}
6574
return result;
6675
}
76+
#endif
6777

78+
#ifdef USE_ZLIB
6879
int def_zlib(cpprcoder::MemoryStream& outStream, cpprcoder::u32 srcSize, cpprcoder::u8* src)
6980
{
7081
int ret, flush;
@@ -156,6 +167,7 @@ int inf_zlib(cpprcoder::MemoryStream& outStream, cpprcoder::u32 srcSize, cpprcod
156167
inflateEnd(&stream);
157168
return ret == Z_STREAM_END ? outCount : Z_DATA_ERROR;
158169
}
170+
#endif
159171

160172
#ifdef USE_LZ4
161173
int def_lz4(cpprcoder::MemoryStream& outStream, cpprcoder::u32 srcSize, cpprcoder::u8* src)
@@ -177,6 +189,7 @@ int inf_lz4(cpprcoder::MemoryStream& outStream, cpprcoder::u32 srcSize, cpprcode
177189
}
178190
#endif
179191

192+
#ifdef USE_RC
180193
void run_rangecoder(const char* filepath)
181194
{
182195
Timer timer;
@@ -223,7 +236,9 @@ void run_rangecoder(const char* filepath)
223236
}
224237
delete[] src;
225238
}
239+
#endif
226240

241+
#ifdef USE_ADAPTIVE
227242
void run_adaptive(const char* filepath)
228243
{
229244
Timer timer;
@@ -281,7 +296,9 @@ void run_adaptive(const char* filepath)
281296
}
282297
delete[] src;
283298
}
299+
#endif
284300

301+
#ifdef USE_SLZ4
285302
void run_slz4(const char* filepath)
286303
{
287304
Timer timer;
@@ -312,19 +329,27 @@ void run_slz4(const char* filepath)
312329
timer.stop();
313330
deflateTime = timer.microseconds();
314331

332+
timer.start();
315333
if(inf_slz4(decstream, encstream.size(), &encstream[0]) < 0) {
316334
delete[] src;
317335
return;
318336
}
319337
timer.stop();
320338
inflateTime = timer.microseconds();
321339

340+
for(size_t i=0; i<decstream.size(); ++i){
341+
if(src[i] != decstream[i]){
342+
return;
343+
}
344+
}
322345
double ratio = (double)encstream.size() / size;
323346
//printf("|%s|%d|%d|%f|%lld|%lld|\n", filepath, size, encstream.size(), ratio, deflateTime, inflateTime);
324347
printf("|%s|%f|%lld|%lld|\n", filepath, ratio, deflateTime, inflateTime);
325348
delete[] src;
326349
}
350+
#endif
327351

352+
#ifdef USE_ZLIB
328353
void run_zlib(const char* filepath)
329354
{
330355
Timer timer;
@@ -353,6 +378,7 @@ void run_zlib(const char* filepath)
353378
timer.stop();
354379
deflateTime = timer.microseconds();
355380

381+
timer.start();
356382
if(inf_zlib(decstream, encstream.size(), &encstream[0]) < 0) {
357383
delete[] src;
358384
return;
@@ -365,6 +391,7 @@ void run_zlib(const char* filepath)
365391
printf("|%s|%f|%lld|%lld|\n", filepath, ratio, deflateTime, inflateTime);
366392
delete[] src;
367393
}
394+
#endif
368395

369396
#ifdef USE_LZ4
370397
void run_lz4(const char* filepath)
@@ -396,7 +423,8 @@ void run_lz4(const char* filepath)
396423
}
397424
timer.stop();
398425
deflateTime = timer.microseconds();
399-
426+
427+
timer.start();
400428
if(inf_lz4(decstream, encstream.size(), &encstream[0]) < 0) {
401429
delete[] src;
402430
return;
@@ -411,6 +439,7 @@ void run_lz4(const char* filepath)
411439
}
412440
#endif
413441

442+
#ifdef USE_RC
414443
bool test_rangecoder()
415444
{
416445
std::mt19937 mt;
@@ -439,7 +468,9 @@ bool test_rangecoder()
439468
}
440469
return true;
441470
}
471+
#endif
442472

473+
#ifdef USE_ADAPTIVE
443474
bool test_adaptive()
444475
{
445476
std::mt19937 mt;
@@ -477,10 +508,11 @@ bool test_adaptive()
477508
}
478509
return true;
479510
}
511+
#endif
480512

481513
int main(int /*argc*/, char** /*argv*/)
482514
{
483-
test_rangecoder();
515+
//test_rangecoder();
484516
//test_adaptive();
485517

486518
const char* files[] =
@@ -499,25 +531,31 @@ int main(int /*argc*/, char** /*argv*/)
499531
};
500532
static const int numFiles = sizeof(files) / (sizeof(files[0]));
501533

534+
#ifdef USE_RC
502535
printf("Range Coder\n");
503536
printf("-------------------------------------------\n");
504537
for(int i = 0; i < numFiles; ++i) {
505538
run_rangecoder(files[i]);
506539
}
540+
#endif
507541

542+
#ifdef USE_ADAPTIVE
508543
printf("Adaptive Range Coder\n");
509544
printf("-------------------------------------------\n");
510545
for(int i = 0; i < numFiles; ++i) {
511546
run_adaptive(files[i]);
512547
}
548+
#endif
513549

550+
#ifdef USE_SLZ4
514551
printf("SLZ4\n");
515552
printf("-------------------------------------------\n");
516553
for(int i = 0; i < numFiles; ++i) {
517554
run_slz4(files[i]);
518555
}
556+
#endif
519557

520-
#if 1
558+
#ifdef USE_ZLIB
521559
printf("ZLib\n");
522560
printf("-------------------------------------------\n");
523561
for(int i = 0; i < numFiles; ++i) {

0 commit comments

Comments
 (0)