Beispiel #1
0
        public void UseHashWhenMatchingMembers()
        {
            Func <TextReader, _UseHashWhenMatchingMembers> hash;
            Func <TextReader, _UseHashWhenMatchingMembers> dictionary;

            Assert.IsTrue(MemberMatcher <_UseHashWhenMatchingMembers> .IsAvailable);

            try
            {
                {
                    InlineDeserializer <_UseHashWhenMatchingMembers> .UseHashWhenMatchingMembers = true;
                    Exception ignored;

                    // Build the *actual* deserializer method
                    hash = InlineDeserializerHelper.Build <_UseHashWhenMatchingMembers>(typeof(Jil.Deserialize.NewtonsoftStyleTypeCache <_UseHashWhenMatchingMembers>), dateFormat: Jil.DateTimeFormat.NewtonsoftStyleMillisecondsSinceUnixEpoch, allowHashing: true, exceptionDuringBuild: out ignored);
                }

                {
                    InlineDeserializer <_UseHashWhenMatchingMembers> .UseHashWhenMatchingMembers = false;
                    Exception ignored;

                    // Build the *actual* deserializer method
                    dictionary = InlineDeserializerHelper.Build <_UseHashWhenMatchingMembers>(typeof(Jil.Deserialize.NewtonsoftStyleTypeCache <_UseHashWhenMatchingMembers>), dateFormat: Jil.DateTimeFormat.NewtonsoftStyleMillisecondsSinceUnixEpoch, allowHashing: true, exceptionDuringBuild: out ignored);
                }
            }
            finally
            {
                InlineDeserializer <_UseHashWhenMatchingMembers> .UseHashWhenMatchingMembers = true;
            }

            var rand = new Random(67982477);

            var toSerialize = new List <_UseHashWhenMatchingMembers>();

            for (var i = 0; i < 2000; i++)
            {
                toSerialize.Add(
                    new _UseHashWhenMatchingMembers
                {
                    accept_rate  = rand.Next(),
                    display_name = _RandString(rand),
                    link         = _RandString(rand),
                    reputation   = rand.Next(),
                    user_id      = rand.Next(),
                    user_type    = _RandEnum <_UseHashWhenMatchingMembers.UserType>(rand)
                }
                    );
            }

            toSerialize = toSerialize.Select(_ => new { _ = _, Order = rand.Next() }).OrderBy(o => o.Order).Select(o => o._).Where((o, ix) => ix % 2 == 0).ToList();

            double hashTime, dictionaryTime;

            CompareTimes(toSerialize, Jil.Options.Default, hash, dictionary, out hashTime, out dictionaryTime);

            Assert.IsTrue(hashTime < dictionaryTime, "hashTime = " + hashTime + ", dictionaryTime = " + dictionaryTime);
        }
Beispiel #2
0
        public void UseNameAutomata()
        {
            Func <TextReader, int, _UseNameAutomata> automata;
            Func <TextReader, int, _UseNameAutomata> dictionary;

            try
            {
                {
                    InlineDeserializer <_UseNameAutomata> .UseNameAutomata = true;
                    Exception ignored;

                    // Build the *actual* deserializer method
                    automata = InlineDeserializerHelper.Build <_UseNameAutomata>(typeof(Jil.Deserialize.NewtonsoftStyle), dateFormat: Jil.DateTimeFormat.NewtonsoftStyleMillisecondsSinceUnixEpoch, exceptionDuringBuild: out ignored);
                }

                {
                    InlineDeserializer <_UseNameAutomata> .UseNameAutomata = false;
                    Exception ignored;

                    // Build the *actual* deserializer method
                    dictionary = InlineDeserializerHelper.Build <_UseNameAutomata>(typeof(Jil.Deserialize.NewtonsoftStyle), dateFormat: Jil.DateTimeFormat.NewtonsoftStyleMillisecondsSinceUnixEpoch, exceptionDuringBuild: out ignored);
                }
            }
            finally
            {
                InlineDeserializer <_UseNameAutomata> .UseNameAutomata = true;
            }

            var rand = new Random(97031664);

            var toSerialize = new List <_UseNameAutomata>();

            for (var i = 0; i < 10000; i++)
            {
                toSerialize.Add(
                    new _UseNameAutomata
                {
                    accept_rate  = rand.Next(),
                    display_name = _RandString(rand),
                    link         = _RandString(rand),
                    reputation   = rand.Next(),
                    user_id      = rand.Next(),
                    user_type    = _RandEnum <_UseNameAutomata.UserType>(rand)
                }
                    );
            }

            toSerialize = toSerialize.Select(_ => new { _ = _, Order = rand.Next() }).OrderBy(o => o.Order).Select(o => o._).Where((o, ix) => ix % 2 == 0).ToList();

            double automataTime, dictionaryTime;

            CompareTimes(toSerialize, Jil.Options.Default, automata, dictionary, out automataTime, out dictionaryTime);

            Assert.IsTrue(automataTime < dictionaryTime, "automataTime = " + automataTime + ", dictionaryTime = " + dictionaryTime);
        }
Beispiel #3
0
        public void UseNameAutomataWhenMatchingEnums()
        {
            Func <TextReader, int, _UseNameAutomataWhenMatchingEnums> automata;
            Func <TextReader, int, _UseNameAutomataWhenMatchingEnums> method;


            try
            {
                {
                    InlineDeserializer <_UseNameAutomataWhenMatchingEnums> .UseNameAutomataForEnums = true;
                    Exception ignored;

                    // Build the *actual* deserializer method
                    automata = InlineDeserializerHelper.Build <_UseNameAutomataWhenMatchingEnums>(typeof(Jil.Deserialize.TypeCache <Jil.Deserialize.NewtonsoftStyle, _UseNameAutomataWhenMatchingEnums>), dateFormat: Jil.DateTimeFormat.NewtonsoftStyleMillisecondsSinceUnixEpoch, exceptionDuringBuild: out ignored);
                }

                {
                    InlineDeserializer <_UseNameAutomataWhenMatchingEnums> .UseNameAutomataForEnums = false;
                    Exception ignored;

                    // Build the *actual* deserializer method
                    method = InlineDeserializerHelper.Build <_UseNameAutomataWhenMatchingEnums>(typeof(Jil.Deserialize.TypeCache <Jil.Deserialize.NewtonsoftStyle, _UseHashWhenMatchingMembers>), dateFormat: Jil.DateTimeFormat.NewtonsoftStyleMillisecondsSinceUnixEpoch, exceptionDuringBuild: out ignored);
                }
            }
            finally
            {
                InlineDeserializer <_UseNameAutomataWhenMatchingEnums> .UseNameAutomataForEnums = true;
            }

            var rand = new Random(191112901);

            var toSerialize = new List <_UseNameAutomataWhenMatchingEnums>();

            for (var i = 0; i < 2000; i++)
            {
                toSerialize.Add(_RandEnum <_UseNameAutomataWhenMatchingEnums>(rand));
            }

            toSerialize = toSerialize.Select(_ => new { _ = _, Order = rand.Next() }).OrderBy(o => o.Order).Select(o => o._).Where((o, ix) => ix % 2 == 0).ToList();

            double automataTime, methodTime;

            CompareTimes(toSerialize, Jil.Options.Default, automata, method, out automataTime, out methodTime);

            Assert.IsTrue(automataTime < methodTime, "automataTime = " + automataTime + ", methodTime = " + methodTime);
        }
Beispiel #4
0
        public void AlwaysUseCharBufferForStrings()
        {
            // objects
            {
                Func <TextReader, _AlwaysUseCharBufferForStrings> fast;
                Func <TextReader, _AlwaysUseCharBufferForStrings> normal;

                try
                {
                    {
                        InlineDeserializer <_AlwaysUseCharBufferForStrings> .AlwaysUseCharBufferForStrings = true;
                        Exception ignored;

                        // Build the *actual* deserializer method
                        fast = InlineDeserializerHelper.Build <_AlwaysUseCharBufferForStrings>(typeof(Jil.Deserialize.NewtonsoftStyleTypeCache <>), dateFormat: Jil.DateTimeFormat.NewtonsoftStyleMillisecondsSinceUnixEpoch, allowHashing: true, exceptionDuringBuild: out ignored);
                    }

                    {
                        InlineDeserializer <_AlwaysUseCharBufferForStrings> .AlwaysUseCharBufferForStrings = false;
                        Exception ignored;

                        // Build the *actual* deserializer method
                        normal = InlineDeserializerHelper.Build <_AlwaysUseCharBufferForStrings>(typeof(Jil.Deserialize.NewtonsoftStyleTypeCache <>), dateFormat: Jil.DateTimeFormat.NewtonsoftStyleMillisecondsSinceUnixEpoch, allowHashing: true, exceptionDuringBuild: out ignored);
                    }
                }
                finally
                {
                    InlineDeserializer <_AlwaysUseCharBufferForStrings> .AlwaysUseCharBufferForStrings = true;
                }

                var rand = new Random(23450051);

                var toSerialize = new List <_AlwaysUseCharBufferForStrings>();
                for (var i = 0; i < 2000; i++)
                {
                    toSerialize.Add(
                        new _AlwaysUseCharBufferForStrings
                    {
                        A = _RandString(rand, 32),
                        B = _RandString(rand, 64)
                    }
                        );
                }

                toSerialize = toSerialize.Select(_ => new { _ = _, Order = rand.Next() }).OrderBy(o => o.Order).Select(o => o._).Where((o, ix) => ix % 2 == 0).ToList();

                double fastTime, normalTime;
                CompareTimes(toSerialize, Jil.Options.Default, fast, normal, out fastTime, out normalTime);

                Assert.IsTrue(fastTime < normalTime, "fastTime = " + fastTime + ", normalTime = " + normalTime);
            }

            // strings
            {
                Func <TextReader, string> fast;
                Func <TextReader, string> normal;

                try
                {
                    {
                        InlineDeserializer <string> .AlwaysUseCharBufferForStrings = true;
                        Exception ignored;

                        // Build the *actual* deserializer method
                        fast = InlineDeserializerHelper.Build <string>(typeof(Jil.Deserialize.NewtonsoftStyleTypeCache <>), dateFormat: Jil.DateTimeFormat.NewtonsoftStyleMillisecondsSinceUnixEpoch, allowHashing: true, exceptionDuringBuild: out ignored);
                    }

                    {
                        InlineDeserializer <string> .AlwaysUseCharBufferForStrings = false;
                        Exception ignored;

                        // Build the *actual* deserializer method
                        normal = InlineDeserializerHelper.Build <string>(typeof(Jil.Deserialize.NewtonsoftStyleTypeCache <>), dateFormat: Jil.DateTimeFormat.NewtonsoftStyleMillisecondsSinceUnixEpoch, allowHashing: true, exceptionDuringBuild: out ignored);
                    }
                }
                finally
                {
                    InlineDeserializer <string> .AlwaysUseCharBufferForStrings = true;
                }

                var rand = new Random(49139290);

                var toSerialize = new List <string>();
                for (var i = 0; i < 2000; i++)
                {
                    toSerialize.Add(_RandString(rand, 32));
                }

                toSerialize = toSerialize.Select(_ => new { _ = _, Order = rand.Next() }).OrderBy(o => o.Order).Select(o => o._).Where((o, ix) => ix % 2 == 0).ToList();

                double fastTime, normalTime;
                CompareTimes(toSerialize, Jil.Options.Default, fast, normal, out fastTime, out normalTime);

                Assert.IsTrue(fastTime < normalTime, "fastTime = " + fastTime + ", normalTime = " + normalTime);
            }
        }