Example #1
0
        private static ulong GetCompressRating(uint dictionarySize, ulong elapsedTime, ulong size)
        {
            long  num1 = (long)(LzmaBench.GetLogSize(dictionarySize) - 4608U);
            ulong num2 = (ulong)(1060L + (long)((ulong)(num1 * num1) * 10UL >> 16));

            return(LzmaBench.MyMultDiv64(size * num2, elapsedTime));
        }
Example #2
0
        private static ulong GetCompressRating(uint dictionarySize, ulong elapsedTime, ulong size)
        {
            ulong num   = (ulong)(LzmaBench.GetLogSize(dictionarySize) - 4608u);
            ulong num2  = 1060uL + (num * num * 10uL >> 16);
            ulong value = size * num2;

            return(LzmaBench.MyMultDiv64(value, elapsedTime));
        }
Example #3
0
 private static ulong GetTotalRating(
     uint dictionarySize,
     ulong elapsedTimeEn,
     ulong sizeEn,
     ulong elapsedTimeDe,
     ulong inSizeDe,
     ulong outSizeDe)
 {
     return((LzmaBench.GetCompressRating(dictionarySize, elapsedTimeEn, sizeEn) + LzmaBench.GetDecompressRating(elapsedTimeDe, inSizeDe, outSizeDe)) / 2UL);
 }
Example #4
0
 private static void PrintResults(
     uint dictionarySize,
     ulong elapsedTime,
     ulong size,
     bool decompressMode,
     ulong secondSize)
 {
     LzmaBench.PrintValue(LzmaBench.MyMultDiv64(size, elapsedTime) / 1024UL);
     Console.Write(" KB/s  ");
     LzmaBench.PrintRating(!decompressMode ? LzmaBench.GetCompressRating(dictionarySize, elapsedTime, size) : LzmaBench.GetDecompressRating(elapsedTime, size, secondSize));
 }
Example #5
0
        private static void PrintResults(uint dictionarySize, ulong elapsedTime, ulong size, bool decompressMode, ulong secondSize)
        {
            ulong num = LzmaBench.MyMultDiv64(size, elapsedTime);

            LzmaBench.PrintValue(num / 1024uL);
            Console.Write(" KB/s  ");
            ulong rating;

            if (decompressMode)
            {
                rating = LzmaBench.GetDecompressRating(elapsedTime, size, secondSize);
            }
            else
            {
                rating = LzmaBench.GetCompressRating(dictionarySize, elapsedTime, size);
            }
            LzmaBench.PrintRating(rating);
        }
Example #6
0
        private static int Main2(string[] args)
        {
            Console.WriteLine("\nLZMA# 4.61  2008-11-23\n");
            if (args.Length == 0)
            {
                LzmaAlone.PrintHelp();
                return(0);
            }
            SwitchForm[] switchForms = new SwitchForm[13];
            int          num1        = 0;

            SwitchForm[] switchFormArray1 = switchForms;
            int          index1           = num1;
            int          num2             = index1 + 1;
            SwitchForm   switchForm1      = new SwitchForm("?", SwitchType.Simple, false);

            switchFormArray1[index1] = switchForm1;
            SwitchForm[] switchFormArray2 = switchForms;
            int          index2           = num2;
            int          num3             = index2 + 1;
            SwitchForm   switchForm2      = new SwitchForm("H", SwitchType.Simple, false);

            switchFormArray2[index2] = switchForm2;
            SwitchForm[] switchFormArray3 = switchForms;
            int          index3           = num3;
            int          num4             = index3 + 1;
            SwitchForm   switchForm3      = new SwitchForm("A", SwitchType.UnLimitedPostString, false, 1);

            switchFormArray3[index3] = switchForm3;
            SwitchForm[] switchFormArray4 = switchForms;
            int          index4           = num4;
            int          num5             = index4 + 1;
            SwitchForm   switchForm4      = new SwitchForm("D", SwitchType.UnLimitedPostString, false, 1);

            switchFormArray4[index4] = switchForm4;
            SwitchForm[] switchFormArray5 = switchForms;
            int          index5           = num5;
            int          num6             = index5 + 1;
            SwitchForm   switchForm5      = new SwitchForm("FB", SwitchType.UnLimitedPostString, false, 1);

            switchFormArray5[index5] = switchForm5;
            SwitchForm[] switchFormArray6 = switchForms;
            int          index6           = num6;
            int          num7             = index6 + 1;
            SwitchForm   switchForm6      = new SwitchForm("LC", SwitchType.UnLimitedPostString, false, 1);

            switchFormArray6[index6] = switchForm6;
            SwitchForm[] switchFormArray7 = switchForms;
            int          index7           = num7;
            int          num8             = index7 + 1;
            SwitchForm   switchForm7      = new SwitchForm("LP", SwitchType.UnLimitedPostString, false, 1);

            switchFormArray7[index7] = switchForm7;
            SwitchForm[] switchFormArray8 = switchForms;
            int          index8           = num8;
            int          num9             = index8 + 1;
            SwitchForm   switchForm8      = new SwitchForm("PB", SwitchType.UnLimitedPostString, false, 1);

            switchFormArray8[index8] = switchForm8;
            SwitchForm[] switchFormArray9 = switchForms;
            int          index9           = num9;
            int          num10            = index9 + 1;
            SwitchForm   switchForm9      = new SwitchForm("MF", SwitchType.UnLimitedPostString, false, 1);

            switchFormArray9[index9] = switchForm9;
            SwitchForm[] switchFormArray10 = switchForms;
            int          index10           = num10;
            int          num11             = index10 + 1;
            SwitchForm   switchForm10      = new SwitchForm("EOS", SwitchType.Simple, false);

            switchFormArray10[index10] = switchForm10;
            SwitchForm[] switchFormArray11 = switchForms;
            int          index11           = num11;
            int          num12             = index11 + 1;
            SwitchForm   switchForm11      = new SwitchForm("SI", SwitchType.Simple, false);

            switchFormArray11[index11] = switchForm11;
            SwitchForm[] switchFormArray12 = switchForms;
            int          index12           = num12;
            int          num13             = index12 + 1;
            SwitchForm   switchForm12      = new SwitchForm("SO", SwitchType.Simple, false);

            switchFormArray12[index12] = switchForm12;
            SwitchForm[] switchFormArray13 = switchForms;
            int          index13           = num13;
            int          numSwitches       = index13 + 1;
            SwitchForm   switchForm13      = new SwitchForm("T", SwitchType.UnLimitedPostString, false, 1);

            switchFormArray13[index13] = switchForm13;
            Parser parser = new Parser(numSwitches);

            try
            {
                parser.ParseStrings(switchForms, args);
            }
            catch
            {
                return(LzmaAlone.IncorrectCommand());
            }
            if (parser[0].ThereIs || parser[1].ThereIs)
            {
                LzmaAlone.PrintHelp();
                return(0);
            }
            ArrayList nonSwitchStrings = parser.NonSwitchStrings;
            int       num14            = 0;

            if (num14 >= nonSwitchStrings.Count)
            {
                return(LzmaAlone.IncorrectCommand());
            }
            ArrayList arrayList1 = nonSwitchStrings;
            int       index14    = num14;
            int       num15      = index14 + 1;
            string    lower1     = ((string)arrayList1[index14]).ToLower();
            bool      flag1      = false;
            int       num16      = 2097152;

            if (parser[3].ThereIs)
            {
                int v;
                if (!LzmaAlone.GetNumber((string)parser[3].PostStrings[0], out v))
                {
                    LzmaAlone.IncorrectCommand();
                }
                num16 = 1 << v;
                flag1 = true;
            }
            string str = "bt4";

            if (parser[8].ThereIs)
            {
                str = (string)parser[8].PostStrings[0];
            }
            string lower2 = str.ToLower();
            int    num17;

            if (lower1 == "b")
            {
                int v = 10;
                if (num15 < nonSwitchStrings.Count)
                {
                    ArrayList arrayList2 = nonSwitchStrings;
                    int       index15    = num15;
                    num17 = index15 + 1;
                    if (!LzmaAlone.GetNumber((string)arrayList2[index15], out v))
                    {
                        v = 10;
                    }
                }
                return(LzmaBench.LzmaBenchmark(v, (uint)num16));
            }
            string path = "";

            if (parser[12].ThereIs)
            {
                path = (string)parser[12].PostStrings[0];
            }
            bool flag2 = false;

            if (lower1 == "e")
            {
                flag2 = true;
            }
            else if (lower1 == "d")
            {
                flag2 = false;
            }
            else
            {
                LzmaAlone.IncorrectCommand();
            }
            bool thereIs = parser[10].ThereIs;
            int  num18   = parser[11].ThereIs ? 1 : 0;

            if (thereIs)
            {
                throw new Exception("Not implemeted");
            }
            if (num15 >= nonSwitchStrings.Count)
            {
                LzmaAlone.IncorrectCommand();
            }
            ArrayList arrayList3 = nonSwitchStrings;
            int       index16    = num15;
            int       num19      = index16 + 1;
            Stream    inStream   = (Stream) new FileStream((string)arrayList3[index16], FileMode.Open, FileAccess.Read);

            if (num18 != 0)
            {
                throw new Exception("Not implemeted");
            }
            if (num19 >= nonSwitchStrings.Count)
            {
                LzmaAlone.IncorrectCommand();
            }
            ArrayList arrayList4 = nonSwitchStrings;
            int       index17    = num19;

            num17 = index17 + 1;
            FileStream fileStream1 = new FileStream((string)arrayList4[index17], FileMode.Create, FileAccess.Write);
            FileStream fileStream2 = (FileStream)null;

            if (path.Length != 0)
            {
                fileStream2 = new FileStream(path, FileMode.Open, FileAccess.Read);
            }
            if (flag2)
            {
                if (!flag1)
                {
                    num16 = 8388608;
                }
                int  v1    = 2;
                int  v2    = 3;
                int  v3    = 0;
                int  v4    = 2;
                int  v5    = 128;
                bool flag3 = parser[9].ThereIs | thereIs;
                if (parser[2].ThereIs && !LzmaAlone.GetNumber((string)parser[2].PostStrings[0], out v4))
                {
                    LzmaAlone.IncorrectCommand();
                }
                if (parser[4].ThereIs && !LzmaAlone.GetNumber((string)parser[4].PostStrings[0], out v5))
                {
                    LzmaAlone.IncorrectCommand();
                }
                if (parser[5].ThereIs && !LzmaAlone.GetNumber((string)parser[5].PostStrings[0], out v2))
                {
                    LzmaAlone.IncorrectCommand();
                }
                if (parser[6].ThereIs && !LzmaAlone.GetNumber((string)parser[6].PostStrings[0], out v3))
                {
                    LzmaAlone.IncorrectCommand();
                }
                if (parser[7].ThereIs && !LzmaAlone.GetNumber((string)parser[7].PostStrings[0], out v1))
                {
                    LzmaAlone.IncorrectCommand();
                }
                CoderPropID[] propIDs = new CoderPropID[8]
                {
                    CoderPropID.DictionarySize,
                    CoderPropID.PosStateBits,
                    CoderPropID.LitContextBits,
                    CoderPropID.LitPosBits,
                    CoderPropID.Algorithm,
                    CoderPropID.NumFastBytes,
                    CoderPropID.MatchFinder,
                    CoderPropID.EndMarker
                };
                object[] properties = new object[8]
                {
                    (object)num16,
                    (object)v1,
                    (object)v2,
                    (object)v3,
                    (object)v4,
                    (object)v5,
                    (object)lower2,
                    (object)flag3
                };
                Encoder encoder = new Encoder();
                encoder.SetCoderProperties(propIDs, properties);
                encoder.WriteCoderProperties((Stream)fileStream1);
                long num20 = !(flag3 | thereIs) ? inStream.Length : -1L;
                for (int index15 = 0; index15 < 8; ++index15)
                {
                    fileStream1.WriteByte((byte)(num20 >> 8 * index15));
                }
                if (fileStream2 != null)
                {
                    CDoubleStream cdoubleStream = new CDoubleStream();
                    cdoubleStream.s1        = (Stream)fileStream2;
                    cdoubleStream.s2        = inStream;
                    cdoubleStream.fileIndex = 0;
                    inStream = (Stream)cdoubleStream;
                    long length = fileStream2.Length;
                    cdoubleStream.skipSize = 0L;
                    if (length > (long)num16)
                    {
                        cdoubleStream.skipSize = length - (long)num16;
                    }
                    fileStream2.Seek(cdoubleStream.skipSize, SeekOrigin.Begin);
                    encoder.SetTrainSize((uint)(length - cdoubleStream.skipSize));
                }
                encoder.Code(inStream, (Stream)fileStream1, -1L, -1L, (ICodeProgress)null);
            }
            else
            {
                if (!(lower1 == "d"))
                {
                    throw new Exception("Command Error");
                }
                byte[] numArray = new byte[5];
                if (inStream.Read(numArray, 0, 5) != 5)
                {
                    throw new Exception("input .lzma is too short");
                }
                Decoder decoder = new Decoder();
                decoder.SetDecoderProperties(numArray);
                if (fileStream2 != null && !decoder.Train((Stream)fileStream2))
                {
                    throw new Exception("can't train");
                }
                long outSize = 0;
                for (int index15 = 0; index15 < 8; ++index15)
                {
                    int num20 = inStream.ReadByte();
                    if (num20 < 0)
                    {
                        throw new Exception("Can't Read 1");
                    }
                    outSize |= (long)(byte)num20 << 8 * index15;
                }
                long inSize = inStream.Length - inStream.Position;
                decoder.Code(inStream, (Stream)fileStream1, inSize, outSize, (ICodeProgress)null);
            }
            return(0);
        }
Example #7
0
        public static int Main2(string[] args)
        {
            System.Console.WriteLine("\nLZMA# 4.61  2008-11-23\n");

            if (args.Length == 0)
            {
                PrintHelp();
                return(0);
            }

            SwitchForm[] kSwitchForms = new SwitchForm[13];
            int          sw           = 0;

            kSwitchForms[sw++] = new SwitchForm("?", SwitchType.Simple, false);
            kSwitchForms[sw++] = new SwitchForm("H", SwitchType.Simple, false);
            kSwitchForms[sw++] = new SwitchForm("A", SwitchType.UnLimitedPostString, false, 1);
            kSwitchForms[sw++] = new SwitchForm("D", SwitchType.UnLimitedPostString, false, 1);
            kSwitchForms[sw++] = new SwitchForm("FB", SwitchType.UnLimitedPostString, false, 1);
            kSwitchForms[sw++] = new SwitchForm("LC", SwitchType.UnLimitedPostString, false, 1);
            kSwitchForms[sw++] = new SwitchForm("LP", SwitchType.UnLimitedPostString, false, 1);
            kSwitchForms[sw++] = new SwitchForm("PB", SwitchType.UnLimitedPostString, false, 1);
            kSwitchForms[sw++] = new SwitchForm("MF", SwitchType.UnLimitedPostString, false, 1);
            kSwitchForms[sw++] = new SwitchForm("EOS", SwitchType.Simple, false);
            kSwitchForms[sw++] = new SwitchForm("SI", SwitchType.Simple, false);
            kSwitchForms[sw++] = new SwitchForm("SO", SwitchType.Simple, false);
            kSwitchForms[sw++] = new SwitchForm("T", SwitchType.UnLimitedPostString, false, 1);


            Parser parser = new Parser(sw);

            try
            {
                parser.ParseStrings(kSwitchForms, args);
            }
            catch
            {
                return(IncorrectCommand());
            }

            if (parser[(int)Key.Help1].ThereIs || parser[(int)Key.Help2].ThereIs)
            {
                PrintHelp();
                return(0);
            }

            System.Collections.ArrayList nonSwitchStrings = parser.NonSwitchStrings;

            int paramIndex = 0;

            if (paramIndex >= nonSwitchStrings.Count)
            {
                return(IncorrectCommand());
            }
            string command = (string)nonSwitchStrings[paramIndex++];

            command = command.ToLower();

            bool  dictionaryIsDefined = false;
            Int32 dictionary          = 1 << 21;

            if (parser[(int)Key.Dictionary].ThereIs)
            {
                Int32 dicLog;
                if (!GetNumber((string)parser[(int)Key.Dictionary].PostStrings[0], out dicLog))
                {
                    IncorrectCommand();
                }
                dictionary          = (Int32)1 << dicLog;
                dictionaryIsDefined = true;
            }
            string mf = "bt4";

            if (parser[(int)Key.MatchFinder].ThereIs)
            {
                mf = (string)parser[(int)Key.MatchFinder].PostStrings[0];
            }
            mf = mf.ToLower();

            if (command == "b")
            {
                const Int32 kNumDefaultItereations = 10;
                Int32       numIterations          = kNumDefaultItereations;
                if (paramIndex < nonSwitchStrings.Count)
                {
                    if (!GetNumber((string)nonSwitchStrings[paramIndex++], out numIterations))
                    {
                        numIterations = kNumDefaultItereations;
                    }
                }
                return(LzmaBench.LzmaBenchmark(numIterations, (UInt32)dictionary));
            }

            string train = "";

            if (parser[(int)Key.Train].ThereIs)
            {
                train = (string)parser[(int)Key.Train].PostStrings[0];
            }

            bool encodeMode = false;

            if (command == "e")
            {
                encodeMode = true;
            }
            else if (command == "d")
            {
                encodeMode = false;
            }
            else
            {
                IncorrectCommand();
            }

            bool stdInMode  = parser[(int)Key.StdIn].ThereIs;
            bool stdOutMode = parser[(int)Key.StdOut].ThereIs;

            Stream inStream = null;

            if (stdInMode)
            {
                throw (new Exception("Not implemeted"));
            }
            else
            {
                if (paramIndex >= nonSwitchStrings.Count)
                {
                    IncorrectCommand();
                }
                string inputName = (string)nonSwitchStrings[paramIndex++];
                inStream = new FileStream(inputName, FileMode.Open, FileAccess.Read);
            }

            FileStream outStream = null;

            if (stdOutMode)
            {
                throw (new Exception("Not implemeted"));
            }
            else
            {
                if (paramIndex >= nonSwitchStrings.Count)
                {
                    IncorrectCommand();
                }
                string outputName = (string)nonSwitchStrings[paramIndex++];
                outStream = new FileStream(outputName, FileMode.Create, FileAccess.Write);
            }

            FileStream trainStream = null;

            if (train.Length != 0)
            {
                trainStream = new FileStream(train, FileMode.Open, FileAccess.Read);
            }

            if (encodeMode)
            {
                if (!dictionaryIsDefined)
                {
                    dictionary = 1 << 23;
                }

                Int32 posStateBits   = 2;
                Int32 litContextBits = 3;                 // for normal files
                // UInt32 litContextBits = 0; // for 32-bit data
                Int32 litPosBits = 0;
                // UInt32 litPosBits = 2; // for 32-bit data
                Int32 algorithm    = 2;
                Int32 numFastBytes = 128;

                bool eos = parser[(int)Key.EOS].ThereIs || stdInMode;

                if (parser[(int)Key.Mode].ThereIs)
                {
                    if (!GetNumber((string)parser[(int)Key.Mode].PostStrings[0], out algorithm))
                    {
                        IncorrectCommand();
                    }
                }

                if (parser[(int)Key.FastBytes].ThereIs)
                {
                    if (!GetNumber((string)parser[(int)Key.FastBytes].PostStrings[0], out numFastBytes))
                    {
                        IncorrectCommand();
                    }
                }
                if (parser[(int)Key.LitContext].ThereIs)
                {
                    if (!GetNumber((string)parser[(int)Key.LitContext].PostStrings[0], out litContextBits))
                    {
                        IncorrectCommand();
                    }
                }
                if (parser[(int)Key.LitPos].ThereIs)
                {
                    if (!GetNumber((string)parser[(int)Key.LitPos].PostStrings[0], out litPosBits))
                    {
                        IncorrectCommand();
                    }
                }
                if (parser[(int)Key.PosBits].ThereIs)
                {
                    if (!GetNumber((string)parser[(int)Key.PosBits].PostStrings[0], out posStateBits))
                    {
                        IncorrectCommand();
                    }
                }

                CoderPropID[] propIDs =
                {
                    CoderPropID.DictionarySize,
                    CoderPropID.PosStateBits,
                    CoderPropID.LitContextBits,
                    CoderPropID.LitPosBits,
                    CoderPropID.Algorithm,
                    CoderPropID.NumFastBytes,
                    CoderPropID.MatchFinder,
                    CoderPropID.EndMarker
                };
                object[] properties =
                {
                    (Int32)(dictionary),
                    (Int32)(posStateBits),
                    (Int32)(litContextBits),
                    (Int32)(litPosBits),
                    (Int32)(algorithm),
                    (Int32)(numFastBytes),
                    mf,
                    eos
                };

                Compression.LZMA.Encoder encoder = new Compression.LZMA.Encoder();
                encoder.SetCoderProperties(propIDs, properties);
                encoder.WriteCoderProperties(outStream);
                Int64 fileSize;
                if (eos || stdInMode)
                {
                    fileSize = -1;
                }
                else
                {
                    fileSize = inStream.Length;
                }
                for (int i = 0; i < 8; i++)
                {
                    outStream.WriteByte((Byte)(fileSize >> (8 * i)));
                }
                if (trainStream != null)
                {
                    CDoubleStream doubleStream = new CDoubleStream();
                    doubleStream.s1        = trainStream;
                    doubleStream.s2        = inStream;
                    doubleStream.fileIndex = 0;
                    inStream = doubleStream;
                    long trainFileSize = trainStream.Length;
                    doubleStream.skipSize = 0;
                    if (trainFileSize > dictionary)
                    {
                        doubleStream.skipSize = trainFileSize - dictionary;
                    }
                    trainStream.Seek(doubleStream.skipSize, SeekOrigin.Begin);
                    encoder.SetTrainSize((uint)(trainFileSize - doubleStream.skipSize));
                }
                encoder.Code(inStream, outStream, -1, -1, null);
            }
            else if (command == "d")
            {
                byte[] properties = new byte[5];
                if (inStream.Read(properties, 0, 5) != 5)
                {
                    throw (new Exception("input .lzma is too short"));
                }
                Compression.LZMA.Decoder decoder = new Compression.LZMA.Decoder();
                decoder.SetDecoderProperties(properties);
                if (trainStream != null)
                {
                    if (!decoder.Train(trainStream))
                    {
                        throw (new Exception("can't train"));
                    }
                }
                long outSize = 0;
                for (int i = 0; i < 8; i++)
                {
                    int v = inStream.ReadByte();
                    if (v < 0)
                    {
                        throw (new Exception("Can't Read 1"));
                    }
                    outSize |= ((long)(byte)v) << (8 * i);
                }
                long compressedSize = inStream.Length - inStream.Position;
                decoder.Code(inStream, outStream, compressedSize, outSize, null);
            }
            else
            {
                throw (new Exception("Command Error"));
            }
            return(0);
        }
Example #8
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);
        }
Example #9
0
 private static void PrintRating(ulong rating)
 {
     LzmaBench.PrintValue(rating / 1000000UL);
     Console.Write(" MIPS");
 }
Example #10
0
 private static ulong GetDecompressRating(ulong elapsedTime, ulong outSize, ulong inSize)
 {
     return(LzmaBench.MyMultDiv64((ulong)((long)inSize * 220L + (long)outSize * 20L), elapsedTime));
 }
Example #11
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);
        }
Example #12
0
        private static ulong GetDecompressRating(ulong elapsedTime, ulong outSize, ulong inSize)
        {
            ulong value = inSize * 220uL + outSize * 20uL;

            return(LzmaBench.MyMultDiv64(value, elapsedTime));
        }
Example #13
0
        private static int Main2(string[] args)
        {
            Console.WriteLine("\nLZMA# 4.61  2008-11-23\n");
            if (args.Length == 0)
            {
                LzmaAlone.PrintHelp();
                return(0);
            }
            SwitchForm[] array       = new SwitchForm[13];
            int          numSwitches = 0;

            array[numSwitches++] = new SwitchForm("?", SwitchType.Simple, false);
            array[numSwitches++] = new SwitchForm("H", SwitchType.Simple, false);
            array[numSwitches++] = new SwitchForm("A", SwitchType.UnLimitedPostString, false, 1);
            array[numSwitches++] = new SwitchForm("D", SwitchType.UnLimitedPostString, false, 1);
            array[numSwitches++] = new SwitchForm("FB", SwitchType.UnLimitedPostString, false, 1);
            array[numSwitches++] = new SwitchForm("LC", SwitchType.UnLimitedPostString, false, 1);
            array[numSwitches++] = new SwitchForm("LP", SwitchType.UnLimitedPostString, false, 1);
            array[numSwitches++] = new SwitchForm("PB", SwitchType.UnLimitedPostString, false, 1);
            array[numSwitches++] = new SwitchForm("MF", SwitchType.UnLimitedPostString, false, 1);
            array[numSwitches++] = new SwitchForm("EOS", SwitchType.Simple, false);
            array[numSwitches++] = new SwitchForm("SI", SwitchType.Simple, false);
            array[numSwitches++] = new SwitchForm("SO", SwitchType.Simple, false);
            array[numSwitches++] = new SwitchForm("T", SwitchType.UnLimitedPostString, false, 1);
            Parser parser = new Parser(numSwitches);

            try
            {
                parser.ParseStrings(array, args);
            }
            catch
            {
                int result = LzmaAlone.IncorrectCommand();
                return(result);
            }
            if (parser[0].ThereIs || parser[1].ThereIs)
            {
                LzmaAlone.PrintHelp();
                return(0);
            }
            ArrayList nonSwitchStrings = parser.NonSwitchStrings;
            int       num = 0;

            if (num >= nonSwitchStrings.Count)
            {
                return(LzmaAlone.IncorrectCommand());
            }
            string text = (string)nonSwitchStrings[num++];

            text = text.ToLower();
            bool flag = false;
            int  num2 = 2097152;

            if (parser[3].ThereIs)
            {
                int num3;
                if (!LzmaAlone.GetNumber((string)parser[3].PostStrings[0], out num3))
                {
                    LzmaAlone.IncorrectCommand();
                }
                num2 = 1 << num3;
                flag = true;
            }
            string text2 = "bt4";

            if (parser[8].ThereIs)
            {
                text2 = (string)parser[8].PostStrings[0];
            }
            text2 = text2.ToLower();
            if (text == "b")
            {
                int numIterations = 10;
                if (num < nonSwitchStrings.Count && !LzmaAlone.GetNumber((string)nonSwitchStrings[num++], out numIterations))
                {
                    numIterations = 10;
                }
                return(LzmaBench.LzmaBenchmark(numIterations, (uint)num2));
            }
            string text3 = string.Empty;

            if (parser[12].ThereIs)
            {
                text3 = (string)parser[12].PostStrings[0];
            }
            bool flag2 = false;

            if (text == "e")
            {
                flag2 = true;
            }
            else if (text == "d")
            {
                flag2 = false;
            }
            else
            {
                LzmaAlone.IncorrectCommand();
            }
            bool thereIs  = parser[10].ThereIs;
            bool thereIs2 = parser[11].ThereIs;

            if (thereIs)
            {
                throw new Exception("Not implemeted");
            }
            if (num >= nonSwitchStrings.Count)
            {
                LzmaAlone.IncorrectCommand();
            }
            string path   = (string)nonSwitchStrings[num++];
            Stream stream = new FileStream(path, FileMode.Open, FileAccess.Read);

            if (thereIs2)
            {
                throw new Exception("Not implemeted");
            }
            if (num >= nonSwitchStrings.Count)
            {
                LzmaAlone.IncorrectCommand();
            }
            string     path2       = (string)nonSwitchStrings[num++];
            FileStream fileStream  = new FileStream(path2, FileMode.Create, FileAccess.Write);
            FileStream fileStream2 = null;

            if (text3.Length != 0)
            {
                fileStream2 = new FileStream(text3, FileMode.Open, FileAccess.Read);
            }
            if (flag2)
            {
                if (!flag)
                {
                    num2 = 8388608;
                }
                int  num4  = 2;
                int  num5  = 3;
                int  num6  = 0;
                int  num7  = 2;
                int  num8  = 128;
                bool flag3 = parser[9].ThereIs || thereIs;
                if (parser[2].ThereIs && !LzmaAlone.GetNumber((string)parser[2].PostStrings[0], out num7))
                {
                    LzmaAlone.IncorrectCommand();
                }
                if (parser[4].ThereIs && !LzmaAlone.GetNumber((string)parser[4].PostStrings[0], out num8))
                {
                    LzmaAlone.IncorrectCommand();
                }
                if (parser[5].ThereIs && !LzmaAlone.GetNumber((string)parser[5].PostStrings[0], out num5))
                {
                    LzmaAlone.IncorrectCommand();
                }
                if (parser[6].ThereIs && !LzmaAlone.GetNumber((string)parser[6].PostStrings[0], out num6))
                {
                    LzmaAlone.IncorrectCommand();
                }
                if (parser[7].ThereIs && !LzmaAlone.GetNumber((string)parser[7].PostStrings[0], out num4))
                {
                    LzmaAlone.IncorrectCommand();
                }
                CoderPropID[] propIDs = new CoderPropID[]
                {
                    CoderPropID.DictionarySize,
                    CoderPropID.PosStateBits,
                    CoderPropID.LitContextBits,
                    CoderPropID.LitPosBits,
                    CoderPropID.Algorithm,
                    CoderPropID.NumFastBytes,
                    CoderPropID.MatchFinder,
                    CoderPropID.EndMarker
                };
                object[] properties = new object[]
                {
                    num2,
                    num4,
                    num5,
                    num6,
                    num7,
                    num8,
                    text2,
                    flag3
                };
                Encoder encoder = new Encoder();
                encoder.SetCoderProperties(propIDs, properties);
                encoder.WriteCoderProperties(fileStream);
                long num9;
                if (flag3 || thereIs)
                {
                    num9 = -1L;
                }
                else
                {
                    num9 = stream.Length;
                }
                for (int i = 0; i < 8; i++)
                {
                    fileStream.WriteByte((byte)(num9 >> 8 * i));
                }
                if (fileStream2 != null)
                {
                    CDoubleStream cDoubleStream = new CDoubleStream();
                    cDoubleStream.s1        = fileStream2;
                    cDoubleStream.s2        = stream;
                    cDoubleStream.fileIndex = 0;
                    stream = cDoubleStream;
                    long length = fileStream2.Length;
                    cDoubleStream.skipSize = 0L;
                    if (length > (long)num2)
                    {
                        cDoubleStream.skipSize = length - (long)num2;
                    }
                    fileStream2.Seek(cDoubleStream.skipSize, SeekOrigin.Begin);
                    encoder.SetTrainSize((uint)(length - cDoubleStream.skipSize));
                }
                encoder.Code(stream, fileStream, -1L, -1L, null);
            }
            else
            {
                if (!(text == "d"))
                {
                    throw new Exception("Command Error");
                }
                byte[] array2 = new byte[5];
                if (stream.Read(array2, 0, 5) != 5)
                {
                    throw new Exception("input .lzma is too short");
                }
                Decoder decoder = new Decoder();
                decoder.SetDecoderProperties(array2);
                if (fileStream2 != null && !decoder.Train(fileStream2))
                {
                    throw new Exception("can't train");
                }
                long num10 = 0L;
                for (int j = 0; j < 8; j++)
                {
                    int num11 = stream.ReadByte();
                    if (num11 < 0)
                    {
                        throw new Exception("Can't Read 1");
                    }
                    num10 |= (long)((byte)num11) << 8 * j;
                }
                long inSize = stream.Length - stream.Position;
                decoder.Code(stream, fileStream, inSize, num10, null);
            }
            return(0);
        }