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 snappy #4

Merged
merged 1 commit into from
Dec 3, 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
38 changes: 38 additions & 0 deletions src/DotCompressorBenchmark.Tools/BenchmarkSnappy.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System.IO;
using System.IO.Compression;
using Snappier;

namespace DotCompressorBenchmark.Tools;

public class BenchmarkSnappy : IBenchmark
{
public string Name { get; }

public BenchmarkSnappy()
{
Name = $"Snappy";
}

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

public static long Compress(byte[] uncompressedBytes, byte[] compressedBytes)
{
using MemoryStream ms = new MemoryStream(compressedBytes);
using (SnappyStream stream = new SnappyStream(ms, CompressionMode.Compress, true))
{
stream.Write(uncompressedBytes, 0, uncompressedBytes.Length);
}

return ms.Position;
}

public static long Decompress(byte[] compressedBytes, long size, byte[] uncompressedBytes)
{
using MemoryStream ms = new MemoryStream(compressedBytes, 0, (int)size);
using SnappyStream stream = new SnappyStream(ms, CompressionMode.Decompress, true);
return stream.Read(uncompressedBytes);
}
}
2 changes: 2 additions & 0 deletions src/DotCompressorBenchmark.Tools/Benchmarks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ public static List<BenchmarkResult> Benchmark(List<string> files)
benchmarks.Add(new BenchmarkZLib(CompressionLevel.Fastest));
//benchmarks.Add(new BenchmarkZLib(CompressionLevel.SmallestSize));

benchmarks.Add(new BenchmarkSnappy());

var results = new List<BenchmarkResult>();
foreach (var file in files)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<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" />
</ItemGroup>

<ItemGroup>
Expand Down