示例#1
0
        private void RunTestEx(object value, int times, ICompressor compressor)
        {
            var vType = value?.GetType() ?? typeof(object);
            //var memStream = new MemoryStream();
            var memStream = new RecycleMemoryStream();
            //var jsonSerializer = new JsonTextSerializer { Compressor = compressor };
            //var ut8JsonSerializer = new Utf8JsonTextSerializer { Compressor = compressor };
            var nBinarySerializer = new NBinarySerializer {
                Compressor = compressor
            };
            var rawBinarySerializer = new RawBinarySerializer {
                Compressor = compressor
            };

            Core.Log.Warning("Running Serializer Test. Use Compressor = {0}", compressor?.EncodingType ?? "(no)");
            Core.Log.WriteEmptyLine();
            Core.Log.InfoBasic("By size:");
            //Core.Log.InfoBasic("\tNewtonsoft Bytes Count: {0}", SerializerSizeProcess(value, vType, jsonSerializer));
            //Core.Log.InfoBasic("\tUTF8Json Bytes Count: {0}", SerializerSizeProcess(value, vType, ut8JsonSerializer));
            Core.Log.InfoBasic("\tNBinary Bytes Count: {0}", SerializerSizeProcess(value, vType, nBinarySerializer));
            Core.Log.InfoBasic("\tRawBinary Bytes Count: {0}", SerializerSizeProcess(value, vType, rawBinarySerializer));
            Core.Log.WriteEmptyLine();
            Console.ReadLine();
            Core.Log.InfoBasic("By Times: {0}", times);
            //SerializerProcess("Json", value, vType, times, jsonSerializer, memStream);
            //SerializerProcess("UTF8Json", value, vType, times, ut8JsonSerializer, memStream);
            SerializerProcess("NBinary", value, vType, times, nBinarySerializer, memStream);
            SerializerProcess("RawBinary", value, vType, times, rawBinarySerializer, memStream);
            Console.ReadLine();
        }
示例#2
0
        private void RunTest(object value, int times, bool useGZip)
        {
            var vType          = value?.GetType() ?? typeof(object);
            var compressor     = useGZip ? CompressorManager.GetByEncodingType("gzip") : null;
            var memStream      = new RecycleMemoryStream();
            var jsonSerializer = new JsonTextSerializer {
                Compressor = compressor
            };
            var xmlSerializer = new XmlTextSerializer {
                Compressor = compressor
            };
            var binarySerializer = new BinaryFormatterSerializer {
                Compressor = compressor
            };
            var ut8JsonSerializer = new Utf8JsonTextSerializer {
                Compressor = compressor
            };
            var msgPackSerializer = new MsgPackSerializer {
                Compressor = compressor
            };
            var nBinarySerializer = new NBinarySerializer {
                Compressor = compressor
            };
            var rawBinarySerializer = new RawBinarySerializer {
                Compressor = compressor
            };
            var wBinarySerializer = new WBinarySerializer {
                Compressor = compressor
            };
            var pwBinarySerializer = new PWBinarySerializer {
                Compressor = compressor
            };

            Core.Log.Warning("Running Serializer Test. Use GZIP = {0}", useGZip);
            Core.Log.WriteEmptyLine();
            Core.Log.InfoBasic("By size:");
            Core.Log.InfoBasic("\tJson Bytes Count: {0}", SerializerSizeProcess(value, vType, jsonSerializer));
            Core.Log.InfoBasic("\tXml Bytes Count: {0}", SerializerSizeProcess(value, vType, xmlSerializer));
            Core.Log.InfoBasic("\tBinaryFormatter Bytes Count: {0}", SerializerSizeProcess(value, vType, binarySerializer));
            Core.Log.InfoBasic("\tUtf8Json Bytes Count: {0}", SerializerSizeProcess(value, vType, ut8JsonSerializer));
            Core.Log.InfoBasic("\tMessagePack Bytes Count: {0}", SerializerSizeProcess(value, vType, msgPackSerializer));
            Core.Log.InfoBasic("\tNBinary Bytes Count: {0}", SerializerSizeProcess(value, vType, nBinarySerializer));
            Core.Log.InfoBasic("\tRawBinary Bytes Count: {0}", SerializerSizeProcess(value, vType, rawBinarySerializer));
            Core.Log.InfoBasic("\tWBinary Bytes Count: {0}", SerializerSizeProcess(value, vType, wBinarySerializer));
            Core.Log.InfoBasic("\tPortable WBinary Bytes Count: {0}", SerializerSizeProcess(value, vType, pwBinarySerializer));
            Core.Log.WriteEmptyLine();
            Core.Log.InfoBasic("By Times: {0}", times);
            SerializerProcess("Json", value, vType, times, jsonSerializer, memStream);
            SerializerProcess("Utf8Json", value, vType, times, ut8JsonSerializer, memStream);
            SerializerProcess("NBinary", value, vType, times, nBinarySerializer, memStream);
            SerializerProcess("RawBinary", value, vType, times, rawBinarySerializer, memStream);
            SerializerProcess("WBinary", value, vType, times, wBinarySerializer, memStream);
            SerializerProcess("PWBinary", value, vType, times, pwBinarySerializer, memStream);
            Console.ReadLine();
        }
示例#3
0
        public void Setup()
        {
            Core.InitDefaults();

            var sTest = new STest
            {
                FirstName = "Daniel",
                LastName  = "Redondo",
                Age       = 35,
                value     = 166
            };

            _data = new List <STest>
            {
                sTest, sTest, sTest, sTest, sTest, sTest,
                sTest, sTest, sTest, sTest, sTest, sTest,
                new STest {
                    FirstName = "Person", LastName = "Person" + "." + 0, Age = 1, Brother = sTest
                },
                new STest {
                    FirstName = "Person", LastName = "Person" + "." + 1, Age = 2, Brother = sTest
                },
                new STest {
                    FirstName = "Person", LastName = "Person" + "." + 2, Age = 3, Brother = sTest
                },
                new STest {
                    FirstName = "Person", LastName = "Person" + "." + 3, Age = 4, Brother = sTest
                },
                new STest {
                    FirstName = "Person", LastName = "Person" + "." + 4, Age = 5, Brother = sTest
                },
                new STest {
                    FirstName = "Person", LastName = "Person" + "." + 5, Age = 6, Brother = sTest
                },
                new STest {
                    FirstName = "Person", LastName = "Person" + "." + 6, Age = 7, Brother = sTest
                },
                new STest {
                    FirstName = "Person", LastName = "Person" + "." + 7, Age = 8, Brother = sTest
                },
                new STest {
                    FirstName = "Person", LastName = "Person" + "." + 8, Age = 9, Brother = sTest
                },
                new STest {
                    FirstName = "Person", LastName = "Person" + "." + 9, Age = 10, Brother = sTest
                },
                new STest {
                    FirstName = "Person", LastName = "Person" + "." + 10, Age = 11
                },
                new STest {
                    FirstName = "Person", LastName = "Person" + "." + 11, Age = 12
                },
                new STest {
                    FirstName = "Person", LastName = "Person" + "." + 12, Age = 13
                },
                new STest {
                    FirstName = "Person", LastName = "Person" + "." + 13, Age = 14
                },
                new STest {
                    FirstName = "Person", LastName = "Person" + "." + 14, Age = 15
                },
                new STest {
                    FirstName = "Person", LastName = "Person" + "." + 15, Age = 16
                },
                new STest {
                    FirstName = "Person", LastName = "Person" + "." + 16, Age = 17
                },
                new STest {
                    FirstName = "Person", LastName = "Person" + "." + 17, Age = 18
                },
                new STest {
                    FirstName = "Person", LastName = "Person" + "." + 18, Age = 19
                },
            };

            _jsonSerializer       = new JsonTextSerializer();
            _binData              = _jsonSerializer.Serialize(_data);
            _jsonSerializerStream = new MemoryStream();
            _jsonSerializer.Serialize(_data, _jsonSerializerStream);

            _xmlSerializer       = new XmlTextSerializer();
            _binData             = _xmlSerializer.Serialize(_data);
            _xmlSerializerStream = new MemoryStream();
            _xmlSerializer.Serialize(_data, _xmlSerializerStream);

            _binSerializer       = new BinaryFormatterSerializer();
            _binData             = _binSerializer.Serialize(_data);
            _binSerializerStream = new MemoryStream();
            _binSerializer.Serialize(_data, _binSerializerStream);

            _utf8jsonSerializer       = new Utf8JsonTextSerializer();
            _binData                  = _utf8jsonSerializer.Serialize(_data);
            _utf8jsonSerializerStream = new MemoryStream();
            _utf8jsonSerializer.Serialize(_data, _utf8jsonSerializerStream);

            _msgPackSerializer       = new MsgPackSerializer();
            _binData                 = _msgPackSerializer.Serialize(_data);
            _msgPackSerializerStream = new MemoryStream();
            _msgPackSerializer.Serialize(_data, _msgPackSerializerStream);

            _nBinary       = new NBinarySerializer();
            _binData       = _nBinary.Serialize(_data);
            _nBinaryStream = new MemoryStream();
            _nBinary.Serialize(_data, _nBinaryStream);

            _rawBinary       = new RawBinarySerializer();
            _binData         = _rawBinary.Serialize(_data);
            _rawBinaryStream = new MemoryStream();
            _rawBinary.Serialize(_data, _rawBinaryStream);
        }