Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add lzma #5

Merged
merged 1 commit into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions src/DotCompressorBenchmark.Tools/BenchmarkLZMA.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using System;
using System.IO;
using SevenZip;
using SevenZip.Compression.LZMA;

namespace DotCompressorBenchmark.Tools;

public class BenchmarkLZMA : IBenchmark
{
public string Name { get; }
private readonly int _level;

public BenchmarkLZMA(int level)
{
_level = level;
Name = $"LZMA 22.1.1 -{_level}";
}


public BenchmarkResult Roundtrip(string filename, byte[] srcBytes, byte[] dstBytes)
{
return Benchmarks.Roundtrip(Name, filename, srcBytes, dstBytes,
(s, d) => Compress(s, d, _level), Decompress);
}

public static long Compress(byte[] srcBytes, byte[] dstBytes, int level)
{
using MemoryStream inStream = new MemoryStream(srcBytes);
using MemoryStream outStream = new MemoryStream(dstBytes);
var encoder = new Encoder();
encoder.SetCoderProperties(new CoderPropID[] { CoderPropID.Algorithm }, new object[] { level });
encoder.WriteCoderProperties(outStream);
outStream.Write(BitConverter.GetBytes((long)srcBytes.Length), 0, 8);
encoder.Code(inStream, outStream, srcBytes.Length, dstBytes.Length, null);

return outStream.Position;
}

public static long Decompress(byte[] srcBytes, long size, byte[] dstBytes)
{
using var inStream = new MemoryStream(srcBytes, 0, (int)size);
using var outStream = new MemoryStream(dstBytes);

byte[] properties = new byte[5];
inStream.Read(properties, 0, 5); // header

byte[] originalSizeBytes = new byte[8];
inStream.Read(originalSizeBytes, 0, 8); // size
long originalSize = BitConverter.ToInt64(originalSizeBytes);

var decoder = new Decoder();
decoder.SetDecoderProperties(properties);
decoder.Code(inStream, outStream, size, dstBytes.Length, null);

return outStream.Position;
}
}
23 changes: 15 additions & 8 deletions src/DotCompressorBenchmark.Tools/Benchmarks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,39 +46,46 @@ public static List<BenchmarkResult> Benchmark(List<string> files)
// FastLZ
benchmarks.Add(new BenchmarkDotFastLZ(1));
benchmarks.Add(new BenchmarkDotFastLZ(2));

// LZ4
foreach (LZ4Level value in Enum.GetValues(typeof(LZ4Level)))
{
benchmarks.Add(new BenchmarkK4osLZ4(value));
}

// Zip
benchmarks.Add(new BenchmarkZip(CompressionLevel.Optimal));
benchmarks.Add(new BenchmarkZip(CompressionLevel.Fastest));
//benchmarks.Add(new BenchmarkZip(CompressionLevel.SmallestSize));

// GZip
benchmarks.Add(new BenchmarkGZip(CompressionLevel.Optimal));
benchmarks.Add(new BenchmarkGZip(CompressionLevel.Fastest));
//benchmarks.Add(new BenchmarkGZip(CompressionLevel.SmallestSize));

// Deflate
benchmarks.Add(new BenchmarkDeflate(CompressionLevel.Optimal));
benchmarks.Add(new BenchmarkDeflate(CompressionLevel.Fastest));
//benchmarks.Add(new BenchmarkDeflate(CompressionLevel.SmallestSize));

// Brotli
benchmarks.Add(new BenchmarkBrotli(CompressionLevel.Optimal));
benchmarks.Add(new BenchmarkBrotli(CompressionLevel.Fastest));
//benchmarks.Add(new BenchmarkBrotli(CompressionLevel.SmallestSize));

// ZLib
benchmarks.Add(new BenchmarkZLib(CompressionLevel.Optimal));
benchmarks.Add(new BenchmarkZLib(CompressionLevel.Fastest));
//benchmarks.Add(new BenchmarkZLib(CompressionLevel.SmallestSize));

benchmarks.Add(new BenchmarkSnappy());

// LZMA
benchmarks.Add(new BenchmarkLZMA(0));
benchmarks.Add(new BenchmarkLZMA(2));
benchmarks.Add(new BenchmarkLZMA(4));
benchmarks.Add(new BenchmarkLZMA(5));
benchmarks.Add(new BenchmarkLZMA(9));

var results = new List<BenchmarkResult>();
foreach (var file in files)
Expand Down Expand Up @@ -118,7 +125,7 @@ public static BenchmarkResult Roundtrip(string name, string filename, byte[] src
var result = new BenchmarkResult();
result.Name = name;
result.FileName = Path.GetFileName(filename);
result.Times = 5;
result.Times = 3;
result.SourceByteLength = srcBytes.Length;
result.Compression.ElapsedWatch = new Stopwatch();
result.Compression.ElapsedWatch.Start();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
<ItemGroup>
<PackageReference Include="DotFastLZ.Compression" Version="2023.10.5" />
<PackageReference Include="K4os.Compression.LZ4" Version="1.3.6" />
<PackageReference Include="EasyCompressor.LZ4" Version="1.4.0" />
<PackageReference Include="Snappier" Version="1.1.3" />
<PackageReference Include="LZMA-SDK" Version="22.1.1" />
</ItemGroup>

<ItemGroup>
Expand All @@ -19,5 +19,4 @@
<Content Include=".github\workflows\publish.yml" />
<Content Include=".github\workflows\release.yml" />
</ItemGroup>

</Project>