Esempio n. 1
0
        public void ReorderMembers()
        {
            Action <TextWriter, _ReorderMembers, int> memoryOrder;
            Action <TextWriter, _ReorderMembers, int> normalOrder;

            try
            {
                {
                    InlineSerializer <_ReorderMembers> .ReorderMembers = true;
                    Exception ignored;

                    // Build the *actual* serializer method
                    memoryOrder = InlineSerializerHelper.Build <_ReorderMembers>(typeof(Jil.Serialize.NewtonsoftStyleTypeCache <>), pretty: false, excludeNulls: false, jsonp: false, dateFormat: DateTimeFormat.NewtonsoftStyleMillisecondsSinceUnixEpoch, includeInherited: false, exceptionDuringBuild: out ignored);
                }

                {
                    InlineSerializer <_ReorderMembers> .ReorderMembers = false;
                    Exception ignored;

                    // Build the *actual* serializer method
                    normalOrder = InlineSerializerHelper.Build <_ReorderMembers>(typeof(Jil.Serialize.NewtonsoftStyleTypeCache <>), pretty: false, excludeNulls: false, jsonp: false, dateFormat: DateTimeFormat.NewtonsoftStyleMillisecondsSinceUnixEpoch, includeInherited: false, exceptionDuringBuild: out ignored);
                }
            }
            finally
            {
                InlineSerializer <_ReorderMembers> .ReorderMembers = true;
            }

            var rand = new Random(1160428);

            var toSerialize = new List <_ReorderMembers>();

            for (var i = 0; i < 10000; i++)
            {
                toSerialize.Add(
                    new _ReorderMembers
                {
                    Bar   = _RandString(rand),
                    Buzz  = ((decimal)rand.NextDouble()) * decimal.MaxValue,
                    Fizz  = rand.NextDouble() * double.MaxValue,
                    Foo   = rand.Next(int.MaxValue),
                    Hello = _RandChar(rand),
                    World = Enumerable.Range(0, rand.Next(100)).Select(s => _RandString(rand)).ToArray()
                }
                    );
            }

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

            double reorderedTime, normalOrderTime;

            CompareTimes(toSerialize, memoryOrder, normalOrder, out reorderedTime, out normalOrderTime, checkCorrectness: false);

            var msg = "reorderedTime = " + reorderedTime + ", normalOrderTime = " + normalOrderTime;

            Assert.IsTrue(reorderedTime < normalOrderTime, msg);
            Console.WriteLine(msg);
        }
Esempio n. 2
0
        public void SkipDateTimeMathMethods()
        {
            Action <TextWriter, _SkipDateTimeMathMethods, int> skipped;
            Action <TextWriter, _SkipDateTimeMathMethods, int> normal;

            try
            {
                {
                    InlineSerializer <_SkipDateTimeMathMethods> .SkipDateTimeMathMethods = true;
                    Exception ignored;

                    // Build the *actual* serializer method
                    skipped = InlineSerializerHelper.Build <_SkipDateTimeMathMethods>(typeof(Jil.Serialize.NewtonsoftStyle), pretty: false, excludeNulls: false, jsonp: false, dateFormat: DateTimeFormat.NewtonsoftStyleMillisecondsSinceUnixEpoch, includeInherited: false, exceptionDuringBuild: out ignored);
                }

                {
                    InlineSerializer <_SkipDateTimeMathMethods> .SkipDateTimeMathMethods = false;
                    Exception ignored;

                    // Build the *actual* serializer method
                    normal = InlineSerializerHelper.Build <_SkipDateTimeMathMethods>(typeof(Jil.Serialize.NewtonsoftStyle), pretty: false, excludeNulls: false, jsonp: false, dateFormat: DateTimeFormat.NewtonsoftStyleMillisecondsSinceUnixEpoch, includeInherited: false, exceptionDuringBuild: out ignored);
                }
            }
            finally
            {
                InlineSerializer <_SkipDateTimeMathMethods> .SkipDateTimeMathMethods = true;
            }

            var rand = new Random(66262484);

            var toSerialize = new List <_SkipDateTimeMathMethods>();

            for (var i = 0; i < 1000; i++)
            {
                var numDates = new DateTime[5 + rand.Next(10)];

                for (var j = 0; j < numDates.Length; j++)
                {
                    numDates[j] = _RandDateTime(rand);
                }

                toSerialize.Add(
                    new _SkipDateTimeMathMethods
                {
                    Dates = numDates
                }
                    );
            }

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

            double skippedTime, normalTime;

            CompareTimes(toSerialize, skipped, normal, out skippedTime, out normalTime);

            Assert.IsTrue(skippedTime < normalTime, "skippedTime = " + skippedTime + ", normalTime = " + normalTime);
        }
Esempio n. 3
0
        public void UseCustomISODateFormatting()
        {
            Action <TextWriter, _UseCustomISODateFormatting, int> skipped;
            Action <TextWriter, _UseCustomISODateFormatting, int> normal;

            try
            {
                {
                    InlineSerializer <_UseCustomISODateFormatting> .UseCustomISODateFormatting = true;
                    Exception ignored;

                    // Build the *actual* serializer method
                    skipped = InlineSerializerHelper.Build <_UseCustomISODateFormatting>(typeof(Jil.Serialize.NewtonsoftStyle), dateFormat: Jil.DateTimeFormat.ISO8601, pretty: false, excludeNulls: false, jsonp: false, includeInherited: false, exceptionDuringBuild: out ignored);
                }

                {
                    InlineSerializer <_UseCustomISODateFormatting> .UseCustomISODateFormatting = false;
                    Exception ignored;

                    // Build the *actual* serializer method
                    normal = InlineSerializerHelper.Build <_UseCustomISODateFormatting>(typeof(Jil.Serialize.NewtonsoftStyle), dateFormat: Jil.DateTimeFormat.ISO8601, pretty: false, excludeNulls: false, jsonp: false, includeInherited: false, exceptionDuringBuild: out ignored);
                }
            }
            finally
            {
                InlineSerializer <_UseCustomISODateFormatting> .UseCustomISODateFormatting = true;
            }

            var rand = new Random(39432715);

            var toSerialize = new List <_UseCustomISODateFormatting>();

            for (var i = 0; i < 1000; i++)
            {
                var numDates = new DateTime[5 + rand.Next(10)];

                for (var j = 0; j < numDates.Length; j++)
                {
                    numDates[j] = _RandDateTime(rand);
                }

                toSerialize.Add(
                    new _UseCustomISODateFormatting
                {
                    Dates = numDates.ToList()
                }
                    );
            }

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

            double skippedTime, normalTime;

            CompareTimes(toSerialize, skipped, normal, out skippedTime, out normalTime);

            Assert.IsTrue(skippedTime < normalTime, "skippedTime = " + skippedTime + ", normalTime = " + normalTime);
        }
Esempio n. 4
0
        public void UseCustomIntegerToString()
        {
            Action <TextWriter, _UseCustomIntegerToString, int> custom;
            Action <TextWriter, _UseCustomIntegerToString, int> normal;

            try
            {
                {
                    InlineSerializer <_UseCustomIntegerToString> .UseCustomIntegerToString = true;
                    Exception ignored;

                    // Build the *actual* serializer method
                    custom = InlineSerializerHelper.Build <_UseCustomIntegerToString>(typeof(Jil.Serialize.NewtonsoftStyle), pretty: false, excludeNulls: false, jsonp: false, dateFormat: DateTimeFormat.NewtonsoftStyleMillisecondsSinceUnixEpoch, includeInherited: false, exceptionDuringBuild: out ignored);
                }

                {
                    InlineSerializer <_UseCustomIntegerToString> .UseCustomIntegerToString = false;
                    Exception ignored;

                    // Build the *actual* serializer method
                    normal = InlineSerializerHelper.Build <_UseCustomIntegerToString>(typeof(Jil.Serialize.NewtonsoftStyle), pretty: false, excludeNulls: false, jsonp: false, dateFormat: DateTimeFormat.NewtonsoftStyleMillisecondsSinceUnixEpoch, includeInherited: false, exceptionDuringBuild: out ignored);
                }
            }
            finally
            {
                InlineSerializer <_UseCustomIntegerToString> .UseCustomIntegerToString = true;
            }

            var rand = new Random(139426720);

            var toSerialize = new List <_UseCustomIntegerToString>();

            for (var i = 0; i < 10000; i++)
            {
                toSerialize.Add(
                    new _UseCustomIntegerToString
                {
                    A = (byte)(101 + rand.Next(155)),
                    B = (sbyte)(101 + rand.Next(27)),
                    C = (short)(101 + rand.Next(1000)),
                    D = (ushort)(101 + rand.Next(1000)),
                    E = 101 + rand.Next(int.MaxValue - 101),
                    F = (uint)(101 + rand.Next(int.MaxValue - 101)),
                    G = (long)(101 + rand.Next(int.MaxValue)),
                    H = (ulong)(101 + rand.Next(int.MaxValue))
                }
                    );
            }

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

            double customTime, normalTime;

            CompareTimes(toSerialize, custom, normal, out customTime, out normalTime);

            Assert.IsTrue(customTime < normalTime, "customTime = " + customTime + ", normalTime = " + normalTime);
        }
Esempio n. 5
0
        public void ReorderMembers()
        {
            Action <TextWriter, _ReorderMembers, int> memoryOrder;
            Action <TextWriter, _ReorderMembers, int> normalOrder;

            try
            {
                {
                    InlineSerializer <_ReorderMembers> .ReorderMembers = true;

                    // Build the *actual* serializer method
                    memoryOrder = InlineSerializerHelper.Build <_ReorderMembers>();
                }

                {
                    InlineSerializer <_ReorderMembers> .ReorderMembers = false;

                    // Build the *actual* serializer method
                    normalOrder = InlineSerializerHelper.Build <_ReorderMembers>();
                }
            }
            finally
            {
                InlineSerializer <_ReorderMembers> .ReorderMembers = true;
            }

            var rand = new Random(1160428);

            var toSerialize = new List <_ReorderMembers>();

            for (var i = 0; i < 10000; i++)
            {
                toSerialize.Add(
                    new _ReorderMembers
                {
                    Bar   = _RandString(rand),
                    Buzz  = ((decimal)rand.NextDouble()) * decimal.MaxValue,
                    Fizz  = rand.NextDouble() * double.MaxValue,
                    Foo   = rand.Next(int.MaxValue),
                    Hello = _RandChar(rand),
                    World = Enumerable.Range(0, rand.Next(100)).Select(s => _RandString(rand)).ToArray()
                }
                    );
            }

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

            double reorderedTime, normalOrderTime;

            CompareTimes(toSerialize, memoryOrder, normalOrder, out reorderedTime, out normalOrderTime, checkCorrectness: false);

            var msg = "reorderedTime = " + reorderedTime + ", normalOrderTime = " + normalOrderTime;

            Assert.IsTrue(reorderedTime < normalOrderTime, msg);
            Console.WriteLine(msg);
        }
Esempio n. 6
0
        public void SkipDateTimeMathMethods()
        {
            Action <TextWriter, _SkipDateTimeMathMethods, int> skipped;
            Action <TextWriter, _SkipDateTimeMathMethods, int> normal;

            try
            {
                {
                    InlineSerializer <_SkipDateTimeMathMethods> .SkipDateTimeMathMethods = true;

                    // Build the *actual* serializer method
                    skipped = InlineSerializerHelper.Build <_SkipDateTimeMathMethods>();
                }

                {
                    InlineSerializer <_SkipDateTimeMathMethods> .SkipDateTimeMathMethods = false;

                    // Build the *actual* serializer method
                    normal = InlineSerializerHelper.Build <_SkipDateTimeMathMethods>();
                }
            }
            finally
            {
                InlineSerializer <_SkipDateTimeMathMethods> .SkipDateTimeMathMethods = true;
            }

            var rand = new Random(66262484);

            var toSerialize = new List <_SkipDateTimeMathMethods>();

            for (var i = 0; i < 1000; i++)
            {
                var numDates = new DateTime[5 + rand.Next(10)];

                for (var j = 0; j < numDates.Length; j++)
                {
                    numDates[j] = _RandDateTime(rand);
                }

                toSerialize.Add(
                    new _SkipDateTimeMathMethods
                {
                    Dates = numDates
                }
                    );
            }

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

            double skippedTime, normalTime;

            CompareTimes(toSerialize, skipped, normal, out skippedTime, out normalTime);

            Assert.IsTrue(skippedTime < normalTime, "skippedTime = " + skippedTime + ", normalTime = " + normalTime);
        }
Esempio n. 7
0
        public void UseCustomIntegerToString()
        {
            Action <TextWriter, _UseCustomIntegerToString, int> custom;
            Action <TextWriter, _UseCustomIntegerToString, int> normal;

            try
            {
                {
                    InlineSerializer <_UseCustomIntegerToString> .UseCustomIntegerToString = true;

                    // Build the *actual* serializer method
                    custom = InlineSerializerHelper.Build <_UseCustomIntegerToString>();
                }

                {
                    InlineSerializer <_UseCustomIntegerToString> .UseCustomIntegerToString = false;

                    // Build the *actual* serializer method
                    normal = InlineSerializerHelper.Build <_UseCustomIntegerToString>();
                }
            }
            finally
            {
                InlineSerializer <_UseCustomIntegerToString> .UseCustomIntegerToString = true;
            }

            var rand = new Random(139426720);

            var toSerialize = new List <_UseCustomIntegerToString>();

            for (var i = 0; i < 10000; i++)
            {
                toSerialize.Add(
                    new _UseCustomIntegerToString
                {
                    A = (byte)(101 + rand.Next(155)),
                    B = (sbyte)(101 + rand.Next(27)),
                    C = (short)(101 + rand.Next(1000)),
                    D = (ushort)(101 + rand.Next(1000)),
                    E = 101 + rand.Next(int.MaxValue - 101),
                    F = (uint)(101 + rand.Next(int.MaxValue - 101)),
                    G = (long)(101 + rand.Next(int.MaxValue)),
                    H = (ulong)(101 + rand.Next(int.MaxValue))
                }
                    );
            }

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

            double customTime, normalTime;

            CompareTimes(toSerialize, custom, normal, out customTime, out normalTime);

            Assert.IsTrue(customTime < normalTime, "customTime = " + customTime + ", normalTime = " + normalTime);
        }
Esempio n. 8
0
        public void SkipNumberFormatting()
        {
            Action <TextWriter, _SkipNumberFormatting, int> skipping;
            Action <TextWriter, _SkipNumberFormatting, int> normal;

            try
            {
                {
                    InlineSerializer <_SkipNumberFormatting> .SkipNumberFormatting = true;
                    Exception ignored;

                    // Build the *actual* serializer method
                    skipping = InlineSerializerHelper.Build <_SkipNumberFormatting>(typeof(Jil.Serialize.NewtonsoftStyleTypeCache <>), pretty: false, excludeNulls: false, jsonp: false, dateFormat: DateTimeFormat.NewtonsoftStyleMillisecondsSinceUnixEpoch, includeInherited: false, exceptionDuringBuild: out ignored);
                }

                {
                    InlineSerializer <_SkipNumberFormatting> .SkipNumberFormatting = false;
                    Exception ignored;

                    // Build the *actual* serializer method
                    normal = InlineSerializerHelper.Build <_SkipNumberFormatting>(typeof(Jil.Serialize.NewtonsoftStyleTypeCache <>), pretty: false, excludeNulls: false, jsonp: false, dateFormat: DateTimeFormat.NewtonsoftStyleMillisecondsSinceUnixEpoch, includeInherited: false, exceptionDuringBuild: out ignored);
                }
            }
            finally
            {
                InlineSerializer <_SkipNumberFormatting> .SkipNumberFormatting = true;
            }

            var rand = new Random(141090045);

            var toSerialize = new List <_SkipNumberFormatting>();

            for (var i = 0; i < 10000; i++)
            {
                toSerialize.Add(
                    new _SkipNumberFormatting
                {
                    A = (byte)rand.Next(101),
                    B = (sbyte)rand.Next(101),
                    C = (short)rand.Next(101),
                    D = (ushort)rand.Next(101),
                    E = rand.Next(101),
                }
                    );
            }

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

            double skippingTime, normalTime;

            CompareTimes(toSerialize, skipping, normal, out skippingTime, out normalTime);

            Assert.IsTrue(skippingTime < normalTime, "skippingTime = " + skippingTime + ", normalTime = " + normalTime);
        }
Esempio n. 9
0
        public void UseFastGuids()
        {
            Action <TextWriter, _UseFastGuids, int> fast;
            Action <TextWriter, _UseFastGuids, int> normal;

            try
            {
                {
                    InlineSerializer <_UseFastGuids> .UseFastGuids = true;
                    Exception ignored;

                    // Build the *actual* serializer method
                    fast = InlineSerializerHelper.Build <_UseFastGuids>(typeof(Jil.Serialize.NewtonsoftStyle), pretty: false, excludeNulls: false, jsonp: false, dateFormat: DateTimeFormat.NewtonsoftStyleMillisecondsSinceUnixEpoch, includeInherited: false, exceptionDuringBuild: out ignored);
                }

                {
                    InlineSerializer <_UseFastGuids> .UseFastGuids = false;
                    Exception ignored;

                    // Build the *actual* serializer method
                    normal = InlineSerializerHelper.Build <_UseFastGuids>(typeof(Jil.Serialize.NewtonsoftStyle), pretty: false, excludeNulls: false, jsonp: false, dateFormat: DateTimeFormat.NewtonsoftStyleMillisecondsSinceUnixEpoch, includeInherited: false, exceptionDuringBuild: out ignored);
                }
            }
            finally
            {
                InlineSerializer <_UseFastGuids> .UseFastGuids = true;
            }

            var rand = new Random(70490340);

            var toSerialize = new List <_UseFastGuids>();

            for (var i = 0; i < 2000; i++)
            {
                toSerialize.Add(
                    new _UseFastGuids
                {
                    A = _RandGuid(rand),
                    B = rand.Next(2) == 0 ? null : (Guid?)_RandGuid(rand),
                    C = Enumerable.Range(0, 7 + rand.Next(8)).Select(_ => _RandGuid(rand)).ToList(),
                    D = Enumerable.Range(0, 5 + rand.Next(5)).ToDictionary(d => _RandString(rand) + _RandString(rand), d => _RandGuid(rand))
                }
                    );
            }

            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, fast, normal, out fastTime, out normalTime);

            Assert.IsTrue(fastTime < normalTime, "fastTime = " + fastTime + ", normalTime = " + normalTime);
        }
Esempio n. 10
0
        public void SkipNumberFormatting()
        {
            Action <TextWriter, _SkipNumberFormatting, int> skipping;
            Action <TextWriter, _SkipNumberFormatting, int> normal;

            try
            {
                {
                    InlineSerializer <_SkipNumberFormatting> .SkipNumberFormatting = true;

                    // Build the *actual* serializer method
                    skipping = InlineSerializerHelper.Build <_SkipNumberFormatting>();
                }

                {
                    InlineSerializer <_SkipNumberFormatting> .SkipNumberFormatting = false;

                    // Build the *actual* serializer method
                    normal = InlineSerializerHelper.Build <_SkipNumberFormatting>();
                }
            }
            finally
            {
                InlineSerializer <_SkipNumberFormatting> .SkipNumberFormatting = true;
            }

            var rand = new Random(141090045);

            var toSerialize = new List <_SkipNumberFormatting>();

            for (var i = 0; i < 10000; i++)
            {
                toSerialize.Add(
                    new _SkipNumberFormatting
                {
                    A = (byte)rand.Next(101),
                    B = (sbyte)rand.Next(101),
                    C = (short)rand.Next(101),
                    D = (ushort)rand.Next(101),
                    E = rand.Next(101),
                }
                    );
            }

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

            double skippingTime, normalTime;

            CompareTimes(toSerialize, skipping, normal, out skippingTime, out normalTime);

            Assert.IsTrue(skippingTime < normalTime, "skippingTime = " + skippingTime + ", normalTime = " + normalTime);
        }
Esempio n. 11
0
        public void UseFastGuids()
        {
            Action <TextWriter, _UseFastGuids, int> fast;
            Action <TextWriter, _UseFastGuids, int> normal;

            try
            {
                {
                    InlineSerializer <_UseFastGuids> .UseFastGuids = true;

                    // Build the *actual* serializer method
                    fast = InlineSerializerHelper.Build <_UseFastGuids>();
                }

                {
                    InlineSerializer <_UseFastGuids> .UseFastGuids = false;

                    // Build the *actual* serializer method
                    normal = InlineSerializerHelper.Build <_UseFastGuids>();
                }
            }
            finally
            {
                InlineSerializer <_UseFastGuids> .UseFastGuids = true;
            }

            var rand = new Random(70490340);

            var toSerialize = new List <_UseFastGuids>();

            for (var i = 0; i < 2000; i++)
            {
                toSerialize.Add(
                    new _UseFastGuids
                {
                    A = _RandGuid(rand),
                    B = rand.Next(2) == 0 ? null : (Guid?)_RandGuid(rand),
                    C = Enumerable.Range(0, 7 + rand.Next(8)).Select(_ => _RandGuid(rand)).ToList(),
                    D = Enumerable.Range(0, 5 + rand.Next(5)).ToDictionary(d => _RandString(rand) + _RandString(rand), d => _RandGuid(rand))
                }
                    );
            }

            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, fast, normal, out fastTime, out normalTime);

            Assert.IsTrue(fastTime < normalTime, "fastTime = " + fastTime + ", normalTime = " + normalTime);
        }
Esempio n. 12
0
        public void UseFastLists()
        {
            Action <TextWriter, _UseFastLists, int> fast;
            Action <TextWriter, _UseFastLists, int> normal;

            try
            {
                {
                    InlineSerializer <_UseFastLists> .UseFastLists = true;

                    // Build the *actual* serializer method
                    fast = InlineSerializerHelper.Build <_UseFastLists>();
                }

                {
                    InlineSerializer <_UseFastLists> .UseFastLists = false;

                    // Build the *actual* serializer method
                    normal = InlineSerializerHelper.Build <_UseFastLists>();
                }
            }
            finally
            {
                InlineSerializer <_UseFastLists> .UseFastLists = true;
            }

            var rand = new Random(2323284);

            var toSerialize = new List <_UseFastLists>();

            for (var i = 0; i < 2000; i++)
            {
                toSerialize.Add(
                    new _UseFastLists
                {
                    A = Enumerable.Range(0, 5 + rand.Next(10)).Select(_ => rand.Next()).ToList(),
                    B = Enumerable.Range(0, 10 + rand.Next(5)).Select(_ => rand.Next()).ToArray(),
                    C = Enumerable.Range(0, 7 + rand.Next(8)).Select(_ => _RandString(rand)).ToList().AsReadOnly()
                }
                    );
            }

            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, fast, normal, out fastTime, out normalTime);

            Assert.IsTrue(fastTime < normalTime, "fastTime = " + fastTime + ", normalTime = " + normalTime);
        }
Esempio n. 13
0
        public void AllocationlessDictionaries()
        {
            Action <TextWriter, _AllocationlessDictionaries, int> allocationless;
            Action <TextWriter, _AllocationlessDictionaries, int> normal;

            try
            {
                {
                    InlineSerializer <_AllocationlessDictionaries> .AllocationlessDictionaries = true;
                    Exception ignored;

                    // Build the *actual* serializer method
                    allocationless = InlineSerializerHelper.Build <_AllocationlessDictionaries>(typeof(Jil.Serialize.NewtonsoftStyle), pretty: false, excludeNulls: false, jsonp: false, dateFormat: DateTimeFormat.NewtonsoftStyleMillisecondsSinceUnixEpoch, includeInherited: false, exceptionDuringBuild: out ignored);
                }

                {
                    InlineSerializer <_AllocationlessDictionaries> .AllocationlessDictionaries = false;
                    Exception ignored;

                    // Build the *actual* serializer method
                    normal = InlineSerializerHelper.Build <_AllocationlessDictionaries>(typeof(Jil.Serialize.NewtonsoftStyle), pretty: false, excludeNulls: false, jsonp: false, dateFormat: DateTimeFormat.NewtonsoftStyleMillisecondsSinceUnixEpoch, includeInherited: false, exceptionDuringBuild: out ignored);
                }
            }
            finally
            {
                InlineSerializer <_AllocationlessDictionaries> .AllocationlessDictionaries = true;
            }

            var rand = new Random(202457890);

            var toSerialize = new List <_AllocationlessDictionaries>();

            for (var i = 0; i < 2000; i++)
            {
                toSerialize.Add(
                    new _AllocationlessDictionaries
                {
                    A = Enumerable.Range(0, 5 + rand.Next(5)).ToDictionary(_ => new string(("" + _)[0], 5 + rand.Next(10)), _ => rand.Next())
                }
                    );
            }

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

            double allocationlessTime, normalTime;

            CompareTimes(toSerialize, allocationless, normal, out allocationlessTime, out normalTime);

            Assert.IsTrue(allocationlessTime < normalTime, "allocationlessTime = " + allocationlessTime + ", normalTime = " + normalTime);
        }
Esempio n. 14
0
        public void UseCustomWriteIntUnrolledSigned()
        {
            Action <TextWriter, _UseCustomWriteIntUnrolledSigned, int> signed;
            Action <TextWriter, _UseCustomWriteIntUnrolledSigned, int> normal;

            try
            {
                {
                    InlineSerializer <_UseCustomWriteIntUnrolledSigned> .UseCustomWriteIntUnrolled = true;
                    Exception ignored;

                    // Build the *actual* serializer method
                    signed = InlineSerializerHelper.Build <_UseCustomWriteIntUnrolledSigned>(typeof(Jil.Serialize.NewtonsoftStyle), pretty: false, excludeNulls: false, jsonp: false, dateFormat: DateTimeFormat.NewtonsoftStyleMillisecondsSinceUnixEpoch, includeInherited: false, exceptionDuringBuild: out ignored);
                }

                {
                    InlineSerializer <_UseCustomWriteIntUnrolledSigned> .UseCustomWriteIntUnrolled = false;
                    Exception ignored;

                    // Build the *actual* serializer method
                    normal = InlineSerializerHelper.Build <_UseCustomWriteIntUnrolledSigned>(typeof(Jil.Serialize.NewtonsoftStyle), pretty: false, excludeNulls: false, jsonp: false, dateFormat: DateTimeFormat.NewtonsoftStyleMillisecondsSinceUnixEpoch, includeInherited: false, exceptionDuringBuild: out ignored);
                }
            }
            finally
            {
                InlineSerializer <_UseCustomWriteIntUnrolledSigned> .UseCustomWriteIntUnrolled = true;
            }

            var rand = new Random(27899810);

            var toSerialize = new List <_UseCustomWriteIntUnrolledSigned>();

            for (var i = 0; i < 1000; i++)
            {
                toSerialize.Add(
                    new _UseCustomWriteIntUnrolledSigned
                {
                    A = Enumerable.Range(0, rand.Next(1, 1000)).Select(_ => rand.Next(2) == 0 ? rand.Next() : -rand.Next()).ToList()
                }
                    );
            }

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

            double signedTime, normalTime;

            CompareTimes(toSerialize, signed, normal, out signedTime, out normalTime);

            Assert.IsTrue(signedTime < normalTime, "signedTime = " + signedTime + ", normalTime = " + normalTime);
        }
Esempio n. 15
0
        public void AllocationlessDictionaries()
        {
            Action <TextWriter, _AllocationlessDictionaries, int> allocationless;
            Action <TextWriter, _AllocationlessDictionaries, int> normal;

            try
            {
                {
                    InlineSerializer <_AllocationlessDictionaries> .AllocationlessDictionaries = true;

                    // Build the *actual* serializer method
                    allocationless = InlineSerializerHelper.Build <_AllocationlessDictionaries>();
                }

                {
                    InlineSerializer <_AllocationlessDictionaries> .AllocationlessDictionaries = false;

                    // Build the *actual* serializer method
                    normal = InlineSerializerHelper.Build <_AllocationlessDictionaries>();
                }
            }
            finally
            {
                InlineSerializer <_AllocationlessDictionaries> .AllocationlessDictionaries = true;
            }

            var rand = new Random(202457890);

            var toSerialize = new List <_AllocationlessDictionaries>();

            for (var i = 0; i < 2000; i++)
            {
                toSerialize.Add(
                    new _AllocationlessDictionaries
                {
                    A = Enumerable.Range(0, 5 + rand.Next(5)).ToDictionary(_ => new string(("" + _)[0], 5 + rand.Next(10)), _ => rand.Next())
                }
                    );
            }

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

            double allocationlessTime, normalTime;

            CompareTimes(toSerialize, allocationless, normal, out allocationlessTime, out normalTime);

            Assert.IsTrue(allocationlessTime < normalTime, "allocationlessTime = " + allocationlessTime + ", normalTime = " + normalTime);
        }
Esempio n. 16
0
        private static void Compile(IEnumerable <int[]> ixs)
        {
            try
            {
                InlineSerializer <ComplexType> .ReorderMembers = false;
                Exception ignored;

                // Build the *actual* serializer method
                var normal = InlineSerializerHelper.Build <ComplexType>(typeof(NewtonsoftStyleTypeCache <>), pretty: false, excludeNulls: false, jsonp: false, dateFormat: Jil.DateTimeFormat.NewtonsoftStyleMillisecondsSinceUnixEpoch, includeInherited: false, exceptionDuringBuild: out ignored);

                MethodCache[NormalKey] = normal;
            }
            finally
            {
                InlineSerializer <ComplexType> .ReorderMembers = true;
            }

            foreach (var ix in ixs)
            {
                foreach (var perm in Permutate(ix))
                {
                    var key = string.Join(",", perm);

                    Console.WriteLine("Compiling: " + key);

                    Utils.MemberOrdering = perm.ToArray();

                    Action <TextWriter, ComplexType, int> mtd;

                    try
                    {
                        Exception ignored;

                        // Build the *actual* serializer method
                        mtd = InlineSerializerHelper.Build <ComplexType>(typeof(NewtonsoftStyleTypeCache <>), pretty: false, excludeNulls: false, jsonp: false, dateFormat: Jil.DateTimeFormat.NewtonsoftStyleMillisecondsSinceUnixEpoch, includeInherited: false, exceptionDuringBuild: out ignored);
                    }
                    finally
                    {
                        Utils.MemberOrdering = new[] { 1, 2, 3, 4 };
                    }

                    MethodCache[key] = mtd;
                }
            }

            Console.WriteLine("\t" + MethodCache.Count + " versions to test");
        }
Esempio n. 17
0
        public void PropagateConstants()
        {
            Action <TextWriter, _PropagateConstants, int> propagated;
            Action <TextWriter, _PropagateConstants, int> normal;

            try
            {
                {
                    InlineSerializer <_PropagateConstants> .PropagateConstants = true;
                    Exception ignored;

                    // Build the *actual* serializer method
                    propagated = InlineSerializerHelper.Build <_PropagateConstants>(typeof(Jil.Serialize.NewtonsoftStyle), pretty: false, excludeNulls: false, jsonp: false, dateFormat: DateTimeFormat.NewtonsoftStyleMillisecondsSinceUnixEpoch, includeInherited: false, exceptionDuringBuild: out ignored);
                }

                {
                    InlineSerializer <_PropagateConstants> .PropagateConstants = false;
                    Exception ignored;

                    // Build the *actual* serializer method
                    normal = InlineSerializerHelper.Build <_PropagateConstants>(typeof(Jil.Serialize.NewtonsoftStyle), pretty: false, excludeNulls: false, jsonp: false, dateFormat: DateTimeFormat.NewtonsoftStyleMillisecondsSinceUnixEpoch, includeInherited: false, exceptionDuringBuild: out ignored);
                }
            }
            finally
            {
                InlineSerializer <_PropagateConstants> .PropagateConstants = true;
            }

            var rand = new Random(202457890);

            var toSerialize = new List <_PropagateConstants>();

            for (var i = 0; i < 2000; i++)
            {
                toSerialize.Add(new _PropagateConstants {
                });
            }

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

            double allocationlessTime, normalTime;

            CompareTimes(toSerialize, propagated, normal, out allocationlessTime, out normalTime);

            Assert.IsTrue(allocationlessTime < normalTime, "propagatedTime = " + allocationlessTime + ", normalTime = " + normalTime);
        }
Esempio n. 18
0
        private static void Compile(IEnumerable <int[]> ixs)
        {
            try
            {
                InlineSerializer <ComplexType> .ReorderMembers = false;

                // Build the *actual* serializer method
                var normal = InlineSerializerHelper.Build <ComplexType>();

                MethodCache[NormalKey] = normal;
            }
            finally
            {
                InlineSerializer <ComplexType> .ReorderMembers = true;
            }

            foreach (var ix in ixs)
            {
                foreach (var perm in Permutate(ix))
                {
                    var key = string.Join(",", perm);

                    Console.WriteLine("Compiling: " + key);

                    Utils.MemberOrdering = perm.ToArray();

                    Action <TextWriter, ComplexType, int> mtd;

                    try
                    {
                        // Build the *actual* serializer method
                        mtd = InlineSerializerHelper.Build <ComplexType>();
                    }
                    finally
                    {
                        Utils.MemberOrdering = new[] { 1, 2, 3, 4 };
                    }

                    MethodCache[key] = mtd;
                }
            }

            Console.WriteLine("\t" + MethodCache.Count + " versions to test");
        }
Esempio n. 19
0
        public static void LoadToString()
        {
            if (StringThunk != null)
            {
                return;
            }

            lock (StringThunkInitLock)
            {
                if (StringThunk != null || StringThunkBeingBuilt)
                {
                    return;
                }
                StringThunkBeingBuilt = true;

                var opts = new TOptions();

                StringThunk = InlineSerializerHelper.BuildToString <T>(typeof(TOptions), pretty: opts.PrettyPrint, excludeNulls: opts.ExcludeNulls, dateFormat: opts.DateFormat, jsonp: opts.JSONP, includeInherited: opts.IncludeInherited, exceptionDuringBuild: out StringThunkExceptionDuringBuild);
            }
        }
Esempio n. 20
0
 static NewtonsoftStylePrettyPrintInheritedTypeCache()
 {
     Thunk = InlineSerializerHelper.Build <T>(typeof(NewtonsoftStylePrettyPrintInheritedTypeCache <>), pretty: true, dateFormat: DateTimeFormat.NewtonsoftStyleMillisecondsSinceUnixEpoch, includeInherited: true);
 }
Esempio n. 21
0
 static ISO8601PrettyPrintExcludeNullsTypeCache()
 {
     Thunk = InlineSerializerHelper.Build <T>(typeof(ISO8601PrettyPrintExcludeNullsTypeCache <>), pretty: true, excludeNulls: true, dateFormat: DateTimeFormat.ISO8601);
 }
Esempio n. 22
0
 static ISO8601ExcludeNullsJSONPTypeCache()
 {
     Thunk = InlineSerializerHelper.Build <T>(typeof(ISO8601ExcludeNullsJSONPTypeCache <>), pretty: false, excludeNulls: true, jsonp: true, dateFormat: DateTimeFormat.ISO8601);
 }
Esempio n. 23
0
 static ISO8601InheritedTypeCache()
 {
     Thunk = InlineSerializerHelper.Build <T>(typeof(ISO8601InheritedTypeCache <>), dateFormat: DateTimeFormat.ISO8601, includeInherited: true);
 }
Esempio n. 24
0
 static NewtonsoftStyleExcludeNullsJSONPInheritedTypeCache()
 {
     Thunk = InlineSerializerHelper.Build <T>(typeof(NewtonsoftStyleExcludeNullsJSONPInheritedTypeCache <>), excludeNulls: true, jsonp: true, dateFormat: DateTimeFormat.NewtonsoftStyleMillisecondsSinceUnixEpoch, includeInherited: true);
 }
Esempio n. 25
0
 static ISO8601PrettyPrintJSONPInheritedTypeCache()
 {
     Thunk = InlineSerializerHelper.Build <T>(typeof(ISO8601PrettyPrintJSONPInheritedTypeCache <>), pretty: true, jsonp: true, dateFormat: DateTimeFormat.ISO8601, includeInherited: true);
 }
Esempio n. 26
0
 static ISO8601ExcludeNullsJSONPInheritedTypeCache()
 {
     Thunk = InlineSerializerHelper.Build <T>(typeof(ISO8601ExcludeNullsJSONPInheritedTypeCache <>), excludeNulls: true, jsonp: true, dateFormat: DateTimeFormat.ISO8601, includeInherited: true);
 }
Esempio n. 27
0
 static SecondsPrettyPrintExcludeNullsTypeCache()
 {
     Thunk = InlineSerializerHelper.Build <T>(typeof(SecondsPrettyPrintExcludeNullsTypeCache <>), pretty: true, excludeNulls: true, dateFormat: DateTimeFormat.SecondsSinceUnixEpoch);
 }
Esempio n. 28
0
 static SecondsExcludeNullsJSONPTypeCache()
 {
     Thunk = InlineSerializerHelper.Build <T>(typeof(SecondsExcludeNullsJSONPTypeCache <>), pretty: false, excludeNulls: true, jsonp: true, dateFormat: DateTimeFormat.SecondsSinceUnixEpoch);
 }
Esempio n. 29
0
 static SecondsInheritedTypeCache()
 {
     Thunk = InlineSerializerHelper.Build <T>(typeof(SecondsInheritedTypeCache <>), dateFormat: DateTimeFormat.SecondsSinceUnixEpoch, includeInherited: true);
 }
Esempio n. 30
0
 static SecondsPrettyPrintJSONPInheritedTypeCache()
 {
     Thunk = InlineSerializerHelper.Build <T>(typeof(SecondsPrettyPrintJSONPInheritedTypeCache <>), pretty: true, jsonp: true, dateFormat: DateTimeFormat.SecondsSinceUnixEpoch, includeInherited: true);
 }