public void DecompressUsingStream(Util.CompressionType type) { string testFilePath = Util.CreateCompressedFile(type); int bufferSize = 1024; var bytes = new byte[bufferSize]; using (MemoryStream brStream = new MemoryStream(File.ReadAllBytes(testFilePath))) foreach (var iteration in Benchmark.Iterations) { using (iteration.StartMeasurement()) for (int i = 0; i < Benchmark.InnerIterationCount; i++) { int retCount = -1; using (BrotliStream brotliDecompressStream = new BrotliStream(brStream, CompressionMode.Decompress, true)) { while (retCount != 0) { retCount = brotliDecompressStream.Read(bytes, 0, bufferSize); } } brStream.Seek(0, SeekOrigin.Begin); } } File.Delete(testFilePath); }
public void Compress(Util.CompressionType type) { byte[] bytes = Util.CreateBytesToCompress(type); foreach (var iteration in Benchmark.Iterations) { byte[] compressed = new byte[bytes.Length]; using (iteration.StartMeasurement()) { Brotli.State state = new Brotli.State(); Brotli.Compress(bytes, compressed, out int consumed, out int writen, ref state); } } }
public void CompressUsingStream(Util.CompressionType type) { byte[] bytes = Util.CreateBytesToCompress(type); foreach (var iteration in Benchmark.Iterations) { string filePath = Util.GetTestFilePath(); FileStream output = File.Create(filePath); using (BrotliStream brotliCompressStream = new BrotliStream(output, CompressionMode.Compress)) { using (iteration.StartMeasurement()) { brotliCompressStream.Write(bytes, 0, bytes.Length); } } File.Delete(filePath); } }
public void Decompress(Util.CompressionType type) { string testFilePath = Util.CreateCompressedFile(type); int bufferSize = 1000000; byte[] data = File.ReadAllBytes(testFilePath); var bytes = new byte[bufferSize]; foreach (var iteration in Benchmark.Iterations) { using (iteration.StartMeasurement()) { for (int i = 0; i < Benchmark.InnerIterationCount; i++) { Brotli.State state = new Brotli.State(); Brotli.Decompress(data, bytes, out int consumed, out int written, ref state); } } } File.Delete(testFilePath); }