static public int LzmaBenchmark(Int32 numIterations, UInt32 dictionarySize) { if (numIterations <= 0) return 0; if (dictionarySize < (1 << 18)) { System.Console.WriteLine("\nError: dictionary size for benchmark must be >= 19 (512 KB)"); return 1; } System.Console.Write("\n Compressing Decompressing\n\n"); Compression.LZMA.Encoder encoder = new Compression.LZMA.Encoder(); Compression.LZMA.Decoder decoder = new Compression.LZMA.Decoder(); CoderPropID[] propIDs = { CoderPropID.DictionarySize, }; object[] properties = { (Int32)(dictionarySize), }; UInt32 kBufferSize = dictionarySize + kAdditionalSize; UInt32 kCompressedBufferSize = (kBufferSize / 2) + kCompressedAdditionalSize; encoder.SetCoderProperties(propIDs, properties); System.IO.MemoryStream propStream = new System.IO.MemoryStream(); encoder.WriteCoderProperties(propStream); byte[] propArray = propStream.ToArray(); CBenchRandomGenerator rg = new CBenchRandomGenerator(); rg.Set(kBufferSize); rg.Generate(); CRC crc = new CRC(); crc.Init(); crc.Update(rg.Buffer, 0, rg.BufferSize); CProgressInfo progressInfo = new CProgressInfo(); progressInfo.ApprovedStart = dictionarySize; UInt64 totalBenchSize = 0; UInt64 totalEncodeTime = 0; UInt64 totalDecodeTime = 0; UInt64 totalCompressedSize = 0; MemoryStream inStream = new MemoryStream(rg.Buffer, 0, (int)rg.BufferSize); MemoryStream compressedStream = new MemoryStream((int)kCompressedBufferSize); CrcOutStream crcOutStream = new CrcOutStream(); for (Int32 i = 0; i < numIterations; i++) { progressInfo.Init(); inStream.Seek(0, SeekOrigin.Begin); compressedStream.Seek(0, SeekOrigin.Begin); encoder.Code(inStream, compressedStream, -1, -1, progressInfo); TimeSpan sp2 = DateTime.UtcNow - progressInfo.Time; UInt64 encodeTime = (UInt64)sp2.Ticks; long compressedSize = compressedStream.Position; if (progressInfo.InSize == 0) throw (new Exception("Internal ERROR 1282")); UInt64 decodeTime = 0; for (int j = 0; j < 2; j++) { compressedStream.Seek(0, SeekOrigin.Begin); crcOutStream.Init(); decoder.SetDecoderProperties(propArray); UInt64 outSize = kBufferSize; System.DateTime startTime = DateTime.UtcNow; decoder.Code(compressedStream, crcOutStream, 0, (Int64)outSize, null); TimeSpan sp = (DateTime.UtcNow - startTime); decodeTime = (ulong)sp.Ticks; if (crcOutStream.GetDigest() != crc.GetDigest()) throw (new Exception("CRC Error")); } UInt64 benchSize = kBufferSize - (UInt64)progressInfo.InSize; PrintResults(dictionarySize, encodeTime, benchSize, false, 0); System.Console.Write(" "); PrintResults(dictionarySize, decodeTime, kBufferSize, true, (ulong)compressedSize); System.Console.WriteLine(); totalBenchSize += benchSize; totalEncodeTime += encodeTime; totalDecodeTime += decodeTime; totalCompressedSize += (ulong)compressedSize; } System.Console.WriteLine("---------------------------------------------------"); PrintResults(dictionarySize, totalEncodeTime, totalBenchSize, false, 0); System.Console.Write(" "); PrintResults(dictionarySize, totalDecodeTime, kBufferSize * (UInt64)numIterations, true, totalCompressedSize); System.Console.WriteLine(" Average"); return 0; }
static public int LzmaBenchmark(Int32 numIterations, UInt32 dictionarySize) { if (numIterations <= 0) { return(0); } if (dictionarySize < (1 << 18)) { System.Console.WriteLine("\nError: dictionary size for benchmark must be >= 19 (512 KB)"); return(1); } System.Console.Write("\n Compressing Decompressing\n\n"); Encoder encoder = new Encoder(); Decoder decoder = new Decoder(); CoderPropID[] propIDs = { CoderPropID.DictionarySize, }; object[] properties = { (Int32)(dictionarySize), }; UInt32 kBufferSize = dictionarySize + kAdditionalSize; UInt32 kCompressedBufferSize = (kBufferSize / 2) + kCompressedAdditionalSize; encoder.SetCoderProperties(propIDs, properties); System.IO.MemoryStream propStream = new System.IO.MemoryStream(); encoder.WriteCoderProperties(propStream); byte[] propArray = propStream.ToArray(); CBenchRandomGenerator rg = new CBenchRandomGenerator(); rg.Set(kBufferSize); rg.Generate(); CRC crc = new CRC(); crc.Init(); crc.Update(rg.Buffer, 0, rg.BufferSize); CProgressInfo progressInfo = new CProgressInfo(); progressInfo.ApprovedStart = dictionarySize; UInt64 totalBenchSize = 0; UInt64 totalEncodeTime = 0; UInt64 totalDecodeTime = 0; UInt64 totalCompressedSize = 0; MemoryStream inStream = new MemoryStream(rg.Buffer, 0, (int)rg.BufferSize); MemoryStream compressedStream = new MemoryStream((int)kCompressedBufferSize); CrcOutStream crcOutStream = new CrcOutStream(); for (Int32 i = 0; i < numIterations; i++) { progressInfo.Init(); inStream.Seek(0, SeekOrigin.Begin); compressedStream.Seek(0, SeekOrigin.Begin); encoder.Code(inStream, compressedStream, -1, -1, progressInfo); TimeSpan sp2 = DateTime.UtcNow - progressInfo.Time; UInt64 encodeTime = (UInt64)sp2.Ticks; long compressedSize = compressedStream.Position; if (progressInfo.InSize == 0) { throw (new Exception("Internal ERROR 1282")); } UInt64 decodeTime = 0; for (int j = 0; j < 2; j++) { compressedStream.Seek(0, SeekOrigin.Begin); crcOutStream.Init(); decoder.SetDecoderProperties(propArray); UInt64 outSize = kBufferSize; System.DateTime startTime = DateTime.UtcNow; decoder.Code(compressedStream, crcOutStream, 0, (Int64)outSize, null); TimeSpan sp = (DateTime.UtcNow - startTime); decodeTime = (ulong)sp.Ticks; if (crcOutStream.GetDigest() != crc.GetDigest()) { throw (new Exception("CRC Error")); } } UInt64 benchSize = kBufferSize - (UInt64)progressInfo.InSize; PrintResults(dictionarySize, encodeTime, benchSize, false, 0); System.Console.Write(" "); PrintResults(dictionarySize, decodeTime, kBufferSize, true, (ulong)compressedSize); System.Console.WriteLine(); totalBenchSize += benchSize; totalEncodeTime += encodeTime; totalDecodeTime += decodeTime; totalCompressedSize += (ulong)compressedSize; } System.Console.WriteLine("---------------------------------------------------"); PrintResults(dictionarySize, totalEncodeTime, totalBenchSize, false, 0); System.Console.Write(" "); PrintResults(dictionarySize, totalDecodeTime, kBufferSize * (UInt64)numIterations, true, totalCompressedSize); System.Console.WriteLine(" Average"); return(0); }
public static int LzmaBenchmark(int numIterations, uint dictionarySize) { if (numIterations <= 0) { return(0); } if (dictionarySize < 262144) { Console.WriteLine("\nError: dictionary size for benchmark must be >= 19 (512 KB)"); return(1); } Console.Write("\n Compressing Decompressing\n\n"); Encoder encoder = new Encoder(); Decoder decoder = new Decoder(); CoderPropID[] propIDs = new CoderPropID[1] { CoderPropID.DictionarySize }; object[] properties = new object[1] { (int)dictionarySize }; uint num = dictionarySize + 6291456; uint capacity = num / 2u + 1024; encoder.SetCoderProperties(propIDs, properties); MemoryStream memoryStream = new MemoryStream(); encoder.WriteCoderProperties(memoryStream); byte[] decoderProperties = memoryStream.ToArray(); CBenchRandomGenerator cBenchRandomGenerator = new CBenchRandomGenerator(); cBenchRandomGenerator.Set(num); cBenchRandomGenerator.Generate(); CRC cRC = new CRC(); cRC.Init(); cRC.Update(cBenchRandomGenerator.Buffer, 0u, cBenchRandomGenerator.BufferSize); CProgressInfo cProgressInfo = new CProgressInfo(); cProgressInfo.ApprovedStart = dictionarySize; ulong num2 = 0uL; ulong num3 = 0uL; ulong num4 = 0uL; ulong num5 = 0uL; MemoryStream memoryStream2 = new MemoryStream(cBenchRandomGenerator.Buffer, 0, (int)cBenchRandomGenerator.BufferSize); MemoryStream memoryStream3 = new MemoryStream((int)capacity); CrcOutStream crcOutStream = new CrcOutStream(); for (int i = 0; i < numIterations; i++) { cProgressInfo.Init(); memoryStream2.Seek(0L, SeekOrigin.Begin); memoryStream3.Seek(0L, SeekOrigin.Begin); encoder.Code(memoryStream2, memoryStream3, -1L, -1L, cProgressInfo); ulong ticks = (ulong)(DateTime.UtcNow - cProgressInfo.Time).Ticks; long position = memoryStream3.Position; if (cProgressInfo.InSize == 0) { throw new Exception("Internal ERROR 1282"); } ulong num6 = 0uL; for (int j = 0; j < 2; j++) { memoryStream3.Seek(0L, SeekOrigin.Begin); crcOutStream.Init(); decoder.SetDecoderProperties(decoderProperties); ulong outSize = num; DateTime utcNow = DateTime.UtcNow; decoder.Code(memoryStream3, crcOutStream, 0L, (long)outSize, null); num6 = (ulong)(DateTime.UtcNow - utcNow).Ticks; if (crcOutStream.GetDigest() != cRC.GetDigest()) { throw new Exception("CRC Error"); } } ulong num7 = (ulong)(num - cProgressInfo.InSize); PrintResults(dictionarySize, ticks, num7, decompressMode: false, 0uL); Console.Write(" "); PrintResults(dictionarySize, num6, num, decompressMode: true, (ulong)position); Console.WriteLine(); num2 += num7; num3 += ticks; num4 += num6; num5 = (ulong)((long)num5 + position); } Console.WriteLine("---------------------------------------------------"); PrintResults(dictionarySize, num3, num2, decompressMode: false, 0uL); Console.Write(" "); PrintResults(dictionarySize, num4, (ulong)(num * numIterations), decompressMode: true, num5); Console.WriteLine(" Average"); return(0); }