-
-
Notifications
You must be signed in to change notification settings - Fork 2
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
7 changed files
with
106 additions
and
54 deletions.
There are no files selected for viewing
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
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
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
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
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
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 System.IO; | ||
using System.IO.Compression; | ||
using ZstdSharp; | ||
|
||
namespace DotCompressorBenchmark.Tools; | ||
|
||
public class BenchmarkZstd : IBenchmark | ||
{ | ||
public string Name { get; } | ||
private readonly int _level; | ||
|
||
public BenchmarkZstd(int level) | ||
{ | ||
_level = level; | ||
Name = $"zstd -{_level.ToString()}"; | ||
} | ||
|
||
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[] uncompressedBytes, byte[] compressedBytes, int level) | ||
{ | ||
using var compressedStream = new MemoryStream(compressedBytes); | ||
using (var cs = new CompressionStream(compressedStream, level)) | ||
{ | ||
cs.Write(uncompressedBytes, 0, uncompressedBytes.Length); | ||
} | ||
|
||
return compressedStream.Position; | ||
} | ||
|
||
public static long Decompress(byte[] compressedBytes, long size, byte[] uncompressedBytes) | ||
{ | ||
using var ms = new MemoryStream(compressedBytes, 0, (int)size); | ||
using var ds = new DecompressionStream(ms); | ||
return ds.Read(uncompressedBytes); | ||
} | ||
} |
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