Skip to content

Commit

Permalink
add snappy
Browse files Browse the repository at this point in the history
  • Loading branch information
ikpil committed Dec 3, 2023
1 parent 207a0b4 commit 7c20a94
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
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

0 comments on commit 7c20a94

Please sign in to comment.