-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
247 additions
and
186 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using DotFastLZ.Compression; | ||
|
||
namespace DotFastLZ.Benchmark; | ||
|
||
public class BenchmarkDotFastLZ : IBenchmark | ||
{ | ||
public string Name => _name; | ||
private string _name; | ||
private int _level; | ||
|
||
public BenchmarkDotFastLZ(int level) | ||
{ | ||
_name = $"DotFastLZ L{level}"; | ||
_level = level; | ||
} | ||
|
||
public BenchmarkResult Start(string filename, byte[] srcBytes, byte[] dstBytes) | ||
{ | ||
var compress = CompressDotFastLZL1; | ||
if (_level == 2) | ||
compress = CompressDotFastLZL2; | ||
|
||
return Benchmarks.Start(Name, filename, srcBytes, dstBytes, compress, DecompressDotFastLZ); | ||
} | ||
|
||
private static long CompressDotFastLZL1(byte[] srcBytes, byte[] dstBytes) | ||
{ | ||
return FastLZ.CompressLevel1(srcBytes, 0, srcBytes.Length, dstBytes); | ||
} | ||
|
||
private static long CompressDotFastLZL2(byte[] srcBytes, byte[] dstBytes) | ||
{ | ||
return FastLZ.CompressLevel2(srcBytes, 0, srcBytes.Length, dstBytes); | ||
} | ||
|
||
private static long DecompressDotFastLZ(byte[] srcBytes, long size, byte[] dstBytes) | ||
{ | ||
return FastLZ.Decompress(srcBytes, size, dstBytes, dstBytes.Length); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
using System; | ||
using K4os.Compression.LZ4; | ||
|
||
namespace DotFastLZ.Benchmark; | ||
|
||
public class BenchmarkK4osLZ4 : IBenchmark | ||
{ | ||
public string Name => _name; | ||
|
||
private string _name; | ||
private LZ4Level _level; | ||
|
||
public BenchmarkK4osLZ4(LZ4Level level) | ||
{ | ||
_level = level; | ||
_name = $"K4os.LZ L{_level.ToString()}"; | ||
|
||
// // K4os LZ4 | ||
// var k4osL01 = Benchmark($"K4os.Compression.LZ4 L00", filename, | ||
// srcBytes.ToArray(), dstBytes, (s, d) => CompressK4osLZ4(s, d, LZ4Level.L00_FAST), DecompressK4osLZ4); | ||
// var k4osL12 = Benchmark($"K4os.Compression.LZ4 L12", filename, | ||
// srcBytes.ToArray(), dstBytes, (s, d) => CompressK4osLZ4(s, d, LZ4Level.L12_MAX), DecompressK4osLZ4); | ||
// var k4osL03HC = Benchmark($"K4os.Compression.LZ4 L03_HC", filename, | ||
// srcBytes.ToArray(), dstBytes, (s, d) => CompressK4osLZ4(s, d, LZ4Level.L03_HC), DecompressK4osLZ4); | ||
// var k4osL09HC = Benchmark($"K4os.Compression.LZ4 L09_HC", filename, | ||
// srcBytes.ToArray(), dstBytes, (s, d) => CompressK4osLZ4(s, d, LZ4Level.L09_HC), DecompressK4osLZ4); | ||
// results.Add(k4osL01); | ||
// results.Add(k4osL12); | ||
// results.Add(k4osL03HC); | ||
// results.Add(k4osL09HC); | ||
// | ||
} | ||
|
||
|
||
public BenchmarkResult Start(string filename, byte[] srcBytes, byte[] dstBytes) | ||
{ | ||
return Benchmarks.Start(Name, filename, srcBytes, dstBytes, | ||
(s, d) => CompressK4osLZ4(s, d, _level), DecompressK4osLZ4); | ||
} | ||
|
||
private static long CompressK4osLZ4(byte[] srcBytes, byte[] dstBytes, LZ4Level level) | ||
{ | ||
var writer = new FixedArrayBufferWriter<byte>(dstBytes); | ||
LZ4Pickler.Pickle(srcBytes, writer, level); | ||
return writer.WrittenCount; | ||
} | ||
|
||
private static long DecompressK4osLZ4(byte[] srcBytes, long size, byte[] dstBytes) | ||
{ | ||
var writer = new FixedArrayBufferWriter<byte>(dstBytes); | ||
LZ4Pickler.Unpickle(srcBytes.AsSpan(0, (int)size), writer); | ||
return writer.WrittenCount; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
using System; | ||
using System.IO; | ||
using System.IO.Compression; | ||
|
||
namespace DotFastLZ.Benchmark; | ||
|
||
public class BenchmarkSystemZip : IBenchmark | ||
{ | ||
public string Name => _name; | ||
|
||
private string _name; | ||
private CompressionLevel _level; | ||
|
||
public BenchmarkSystemZip(CompressionLevel level) | ||
{ | ||
_level = level; | ||
_name = $"System.Io.Zip {_level.ToString()}"; | ||
} | ||
|
||
public BenchmarkResult Start(string filename, byte[] srcBytes, byte[] dstBytes) | ||
{ | ||
return Benchmarks.Start(Name, filename, srcBytes, dstBytes, (s, d) => CompressZip(s, d, _level), DecompressZip); | ||
} | ||
|
||
private static long CompressZip(byte[] srcBytes, byte[] dstBytes, CompressionLevel level) | ||
{ | ||
using var ms = new MemoryStream(); | ||
using (var zip = new ZipArchive(ms, ZipArchiveMode.Create)) | ||
{ | ||
var entry = zip.CreateEntry("test", level); | ||
using var s = entry.Open(); | ||
s.Write(srcBytes, 0, srcBytes.Length); | ||
} | ||
|
||
var ssss = ms.ToArray().AsSpan(); | ||
ssss.CopyTo(dstBytes); | ||
return ssss.Length; | ||
} | ||
|
||
private static long DecompressZip(byte[] srcBytes, long size, byte[] dstBytes) | ||
{ | ||
using var readStream = new MemoryStream(srcBytes, 0, (int)size); | ||
using var zip = new ZipArchive(readStream, ZipArchiveMode.Read); | ||
var entry = zip.Entries[0]; | ||
using var entryStream = entry.Open(); | ||
using MemoryStream writeStream = new MemoryStream(dstBytes); | ||
entryStream.CopyTo(writeStream); | ||
return writeStream.Position; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.