示例#1
0
        public static int LzmaBenchmark(int numIterations, uint dictionarySize)
        {
            if (numIterations <= 0)
            {
                return(0);
            }
            if (dictionarySize < 262144U)
            {
                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]
            {
                (object)(int)dictionarySize
            };
            uint bufferSize = dictionarySize + 6291456U;
            int  capacity   = (int)(bufferSize / 2U) + 1024;

            encoder.SetCoderProperties(propIDs, properties);
            MemoryStream memoryStream1 = new MemoryStream();

            encoder.WriteCoderProperties((Stream)memoryStream1);
            byte[] array = memoryStream1.ToArray();
            LzmaBench.CBenchRandomGenerator cbenchRandomGenerator = new LzmaBench.CBenchRandomGenerator();
            cbenchRandomGenerator.Set(bufferSize);
            cbenchRandomGenerator.Generate();
            CRC crc = new CRC();

            crc.Init();
            crc.Update(cbenchRandomGenerator.Buffer, 0U, cbenchRandomGenerator.BufferSize);
            LzmaBench.CProgressInfo cprogressInfo = new LzmaBench.CProgressInfo();
            cprogressInfo.ApprovedStart = (long)dictionarySize;
            ulong        size1         = 0;
            ulong        elapsedTime1  = 0;
            ulong        elapsedTime2  = 0;
            ulong        secondSize    = 0;
            MemoryStream memoryStream2 = new MemoryStream(cbenchRandomGenerator.Buffer, 0, (int)cbenchRandomGenerator.BufferSize);
            MemoryStream memoryStream3 = new MemoryStream(capacity);

            LzmaBench.CrcOutStream crcOutStream = new LzmaBench.CrcOutStream();
            for (int index1 = 0; index1 < numIterations; ++index1)
            {
                cprogressInfo.Init();
                memoryStream2.Seek(0L, SeekOrigin.Begin);
                memoryStream3.Seek(0L, SeekOrigin.Begin);
                encoder.Code((Stream)memoryStream2, (Stream)memoryStream3, -1L, -1L, (ICodeProgress)cprogressInfo);
                ulong ticks    = (ulong)(DateTime.UtcNow - cprogressInfo.Time).Ticks;
                long  position = memoryStream3.Position;
                if (cprogressInfo.InSize == 0L)
                {
                    throw new Exception("Internal ERROR 1282");
                }
                ulong elapsedTime3 = 0;
                for (int index2 = 0; index2 < 2; ++index2)
                {
                    memoryStream3.Seek(0L, SeekOrigin.Begin);
                    crcOutStream.Init();
                    decoder.SetDecoderProperties(array);
                    ulong    num    = (ulong)bufferSize;
                    DateTime utcNow = DateTime.UtcNow;
                    decoder.Code((Stream)memoryStream3, (Stream)crcOutStream, 0L, (long)num, (ICodeProgress)null);
                    elapsedTime3 = (ulong)(DateTime.UtcNow - utcNow).Ticks;
                    if ((int)crcOutStream.GetDigest() != (int)crc.GetDigest())
                    {
                        throw new Exception("CRC Error");
                    }
                }
                ulong size2 = (ulong)bufferSize - (ulong)cprogressInfo.InSize;
                LzmaBench.PrintResults(dictionarySize, ticks, size2, false, 0UL);
                Console.Write("     ");
                LzmaBench.PrintResults(dictionarySize, elapsedTime3, (ulong)bufferSize, true, (ulong)position);
                Console.WriteLine();
                size1        += size2;
                elapsedTime1 += ticks;
                elapsedTime2 += elapsedTime3;
                secondSize   += (ulong)position;
            }
            Console.WriteLine("---------------------------------------------------");
            LzmaBench.PrintResults(dictionarySize, elapsedTime1, size1, false, 0UL);
            Console.Write("     ");
            LzmaBench.PrintResults(dictionarySize, elapsedTime2, (ulong)bufferSize * (ulong)numIterations, true, secondSize);
            Console.WriteLine("    Average");
            return(0);
        }
示例#2
0
        public static int LzmaBenchmark(int numIterations, uint dictionarySize)
        {
            if (numIterations <= 0)
            {
                return(0);
            }
            if (dictionarySize < 262144u)
            {
                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[]
            {
                CoderPropID.DictionarySize
            };
            object[] properties = new object[]
            {
                (int)dictionarySize
            };
            uint num      = dictionarySize + 6291456u;
            uint capacity = num / 2u + 1024u;

            encoder.SetCoderProperties(propIDs, properties);
            MemoryStream memoryStream = new MemoryStream();

            encoder.WriteCoderProperties(memoryStream);
            byte[] decoderProperties = memoryStream.ToArray();
            LzmaBench.CBenchRandomGenerator cBenchRandomGenerator = new LzmaBench.CBenchRandomGenerator();
            cBenchRandomGenerator.Set(num);
            cBenchRandomGenerator.Generate();
            CRC cRC = new CRC();

            cRC.Init();
            cRC.Update(cBenchRandomGenerator.Buffer, 0u, cBenchRandomGenerator.BufferSize);
            LzmaBench.CProgressInfo cProgressInfo = new LzmaBench.CProgressInfo();
            cProgressInfo.ApprovedStart = (long)((ulong)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);

            LzmaBench.CrcOutStream crcOutStream = new LzmaBench.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 == 0L)
                {
                    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 = (ulong)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 - (ulong)cProgressInfo.InSize;
                LzmaBench.PrintResults(dictionarySize, ticks, num7, false, 0uL);
                Console.Write("     ");
                LzmaBench.PrintResults(dictionarySize, num6, (ulong)num, true, (ulong)position);
                Console.WriteLine();
                num2 += num7;
                num3 += ticks;
                num4 += num6;
                num5 += (ulong)position;
            }
            Console.WriteLine("---------------------------------------------------");
            LzmaBench.PrintResults(dictionarySize, num3, num2, false, 0uL);
            Console.Write("     ");
            LzmaBench.PrintResults(dictionarySize, num4, (ulong)num * (ulong)((long)numIterations), true, num5);
            Console.WriteLine("    Average");
            return(0);
        }