예제 #1
0
        public void MsgPackSerialize()
        {
            string val = "abc个";
            byte[] buffer = new byte[7];
            buffer[0] = 166;
            buffer[1] = 97;
            buffer[2] = 98;
            buffer[3] = 99;
            buffer[4] = 228;
            buffer[5] = 184;
            buffer[6] = 170;

            IDataSerializer serializer = SerializerFactory.Create(SerializerType.MsgPack);

            //byte[] data = serializer.Serialize(val);
            //CollectionAssert.AreEqual(data, buffer);

            //string val_res = serializer.Deserialize<string>(buffer);
            //Assert.AreEqual(val, val_res);

            Mall mall = new Mall()
            {
                ID = 1,
                Name = "大悦城",
                GroupID = 135,
                AAAAAAAAAA = "aaaa",
                BBBBBBBBBB = "BBBB",
                CCCCCCCCCC = "hygfjrt7kuylkhgliu;oi;yhdhtfjhsj",
                D = "kuykj687jrstskhgfk",
                EEEEEEEEEE = "jhlhlgjhkuykjuyt",
                F = "djsgfjdjg",
                G = "fdsgasdgs",
                HHHHHHHHHH = "hgfdhergfdhs",
                I = "fdjnhterjrgtas",
                J = "fdhs5htrjgfdfdg",
                User = new User()
                {
                    Date = DateTime.Now,
                    ID = 132414,
                    Name = "ggsgshahsahsdha"
                }
            };

            var json = serializer.Serialize(mall);
            var mall2 = serializer.Deserialize<Mall>(json);
            Assert.AreEqual(mall.Name, mall2.Name);


            User user = new User() { Date = DateTime.Now, Date2 = DateTime.Now, ID = 1243321, Name = "ggsgdhddfhfdhdsg", A = 55555 };
            json = serializer.Serialize(user);
            var user2 = serializer.Deserialize<User2>(json);


            User1 user1 = new User1() { Date = DateTime.Now, Date2 = DateTime.Now, ID = 1243321, Name = "ggsgdhddfhfdhdsg" };
            json = serializer.Serialize(user1);
            user2 = serializer.Deserialize<User2>(json);
        }
예제 #2
0
        public static void NewtonsoftTestBson(int seed)
        {
            NewtsBsonSerializer serializer = new NewtsBsonSerializer();
            Mall mall = new Mall() { ID = 1, Name = "大悦城", GroupID = 135 };
            Stopwatch sw = new Stopwatch();
            byte[] data = null;

            sw.Restart();
            for (var i = 0; i < seed; i++)
            {
                data = serializer.Serialize(mall);
            }
            sw.Stop();

            Console.WriteLine("NewtonsoftTest Bson Serialize:{0}ms", sw.ElapsedMilliseconds);

            sw.Restart();
            for (var i = 0; i < seed; i++)
            {
                mall = serializer.Deserialize<Mall>(data);
            }
            sw.Stop();

            Console.WriteLine("NewtonsoftTest Bson Deserialize:{0}ms", sw.ElapsedMilliseconds);
        }
예제 #3
0
        static void Main(string[] args)
        {
            //while (true)
            //{
            //    SpinWait.SpinUntil(() => false, 1);
            //    //Thread.Sleep(1);
            //    Console.WriteLine(DateTime.Now.ToString());
            //}


            string[] arr = new string[] { "UID", "ProjectType", "Token", "CreateTime", "Timeout" };
            

            Mall mall = new Mall()
            {
                ID = 1,
                Date = DateTime.Now,
                Name = "大悦城",
                GroupID = 135,
                AAAAAAAAAA = "aaaa",
                BBBBBBBBBB = "BBBB",
                CCCCCCCCCC = "hygfjrt7kuylkhgliu;oi;yhdhtfjhsj",
                D = "kuykj687jrstskhgfk",
                EEEEEEEEEE = "jhlhlgjhkuykjuyt",
                F = "djsgfjdjg",
                G = "fdsgasdgs",
                HHHHHHHHHH = "hgfdhergfdhs",
                I = "fdjnhterjrgtas",
                J = "fdhs5htrjgfdfdg",
                User = new User()
                {
                    Date = DateTime.Now,
                    ID = 132414,
                    Name = "ggsgshahsahsdha"
                }
            };
            
            int seed = 100000;

            IDataSerializer serializer1 = SerializerFactory.Create(SerializerType.NewtonsoftJson);
            IDataSerializer serializer2 = SerializerFactory.Create(SerializerType.Jil);

            var data = serializer2.Serialize(mall);
            var mall2 = serializer1.Deserialize<Mall>(data);

            //var res = JSON.Serialize(mall, Options.ISO8601);
            //Console.WriteLine(res);
            //var mall2 = JSON.Deserialize<Mall>(res);
            //mall2.User.Date = mall.User.Date.ToLocalTime();


            Console.WriteLine("序列化数据次数:{0:N0}", seed);

            SpinWait.SpinUntil(() => false, 500);
            Factory(seed, SerializerType.Jil, mall);

            SpinWait.SpinUntil(() => false, 500);
            MsgPackTest(seed, mall);

            SpinWait.SpinUntil(() => false, 500);
            Factory(seed, SerializerType.MsgPack, mall);

            SpinWait.SpinUntil(() => false, 500);
            Factory(seed, SerializerType.NewtonsoftBson, mall);

            SpinWait.SpinUntil(() => false, 500);
            Factory(seed, SerializerType.NewtonsoftJson, mall);

            SpinWait.SpinUntil(() => false, 500);
            Factory(seed, SerializerType.MongoDBBson, mall);

            Console.WriteLine("over......");

            //SpinWait.SpinUntil(() => false, 500);
            //ProtobufTest(seed);

            //SpinWait.SpinUntil(() => false, 500);
            //MsgPackTest(seed);

            //SpinWait.SpinUntil(() => false, 500);
            //JilTest(seed);

            //SpinWait.SpinUntil(() => false, 500);
            //NewtonsoftTest(seed);

            //SpinWait.SpinUntil(() => false, 500);
            //NewtonsoftTestBson(seed);

            Console.ReadLine();
        }
예제 #4
0
        public static void MsgPackTest(int seed, Mall mall)
        {
            //MsgPackSerializer serializer = new MsgPackSerializer();
            IMessagePackSingleObjectSerializer serializer = MsgPack.Serialization.MessagePackSerializer.Get(typeof(Mall));
            Stopwatch sw = new Stopwatch();
            byte[] data = null;

            sw.Restart();
            for (var i = 0; i < seed; i++)
            {
                data = serializer.PackSingleObject(mall);
                //data = serializer.Serialize(mall);
            }
            sw.Stop();

            Console.WriteLine("MsgPackTest Serialize:{0}ms", sw.ElapsedMilliseconds);

            sw.Restart();
            for (var i = 0; i < seed; i++)
            {
                //mall = serializer.UnpackSingleObject(data);
                mall = (Mall)serializer.UnpackSingleObject(data);
                //mall = serializer.Deserialize<Mall>(data);
            }
            sw.Stop();

            Console.WriteLine("MsgPackTest Deserialize:{0}ms", sw.ElapsedMilliseconds);
        }
예제 #5
0
        public static void Factory(int seed, SerializerType type, Mall mall)
        {
            //var serializer = global::MsgPack.Serialization.MessagePackSerializer.Get<Mall>();
            IDataSerializer serializer = SerializerFactory.Create(type);
            Stopwatch sw = new Stopwatch();
            byte[] data = null;

            sw.Restart();
            for (var i = 0; i < seed; i++)
            {
                data = serializer.Serialize(mall);
            }
            sw.Stop();

            Console.WriteLine("{1} Serialize:{0}ms", sw.ElapsedMilliseconds, serializer.GetType().Name);

            sw.Restart();
            for (var i = 0; i < seed; i++)
            {
                mall = serializer.Deserialize<Mall>(data);
            }
            sw.Stop();

            Console.WriteLine("{1} Deserialize:{0}ms", sw.ElapsedMilliseconds, serializer.GetType().Name);
        }
예제 #6
0
        public static void ProtobufTest(int seed)
        {
            ProtobufSerializer serializer = new ProtobufSerializer();
            Mall mall = new Mall() { ID = 1, Name = "大悦城", GroupID = 135 };
            Stopwatch sw = new Stopwatch();
            byte[] data = null;

            sw.Restart();
            for (var i = 0; i < seed; i++)
            {
                data = serializer.Serialize(mall);
            }
            sw.Stop();

            Console.WriteLine("ProtobufTest Serialize:{0}ms", sw.ElapsedMilliseconds);

            SpinWait.SpinUntil(() => false, 500);
            sw.Restart();
            for (var i = 0; i < seed; i++)
            {
                mall = serializer.Deserialize<Mall>(data);
            }
            sw.Stop();

            Console.WriteLine("ProtobufTest Deserialize:{0}ms", sw.ElapsedMilliseconds);
        }
예제 #7
0
        public void JilTest()
        {
            string val = "abc个";
            //byte[] buffer = new byte[7];

            IDataSerializer serializer = SerializerFactory.Create(SerializerType.Jil);

            var data = serializer.Serialize(val);
            //CollectionAssert.AreEqual(data, buffer);

            var val_res = serializer.Deserialize<string>(data);
            Assert.AreEqual(val, val_res);

            Mall mall = new Mall()
            {
                ID = 1,
                Name = "大悦城",
                GroupID = 135,
                AAAAAAAAAA = "aaaa",
                BBBBBBBBBB = "BBBB",
                CCCCCCCCCC = "hygfjrt7kuylkhgliu;oi;yhdhtfjhsj",
                D = "kuykj687jrstskhgfk",
                EEEEEEEEEE = "jhlhlgjhkuykjuyt",
                F = "djsgfjdjg",
                G = "fdsgasdgs",
                HHHHHHHHHH = "hgfdhergfdhs",
                I = "fdjnhterjrgtas",
                J = "fdhs5htrjgfdfdg",
                User = new User()
                {
                    Date = DateTime.Now,
                    ID = 132414,
                    Name = "ggsgshahsahsdha"
                }
            };

            var json = serializer.Serialize(mall);
            var mall2 = serializer.Deserialize<Mall>(json);
            Assert.AreEqual(mall.Name, mall2.Name);


            serializer.Serialize(mall);
            Encoding encoding = Encoding.UTF8;
            var res = encoding.GetString(data);
            var res2 = JSON.Serialize(mall);
            var res3 = JSON.Deserialize<string>(res2, Options.Utc);
            Assert.AreEqual(res, res3);

        }
예제 #8
0
        public void MongoDBTest()
        {
            IDataSerializer serializer = SerializerFactory.Create(SerializerType.MongoDBBson);

            Mall mall = new Mall()
            {
                ID = 1,
                Name = "大悦城",
                GroupID = 135,
                AAAAAAAAAA = "aaaa",
                BBBBBBBBBB = "BBBB",
                CCCCCCCCCC = "hygfjrt7kuylkhgliu;oi;yhdhtfjhsj",
                D = "kuykj687jrstskhgfk",
                EEEEEEEEEE = "jhlhlgjhkuykjuyt",
                F = "djsgfjdjg",
                G = "fdsgasdgs",
                HHHHHHHHHH = "hgfdhergfdhs",
                I = "fdjnhterjrgtas",
                J = "fdhs5htrjgfdfdg",
                User = new User()
                {
                    Date = DateTime.Now,
                    ID = 132414,
                    Name = "ggsgshahsahsdha"
                }
            };

            var json = serializer.Serialize(mall);
            var mall2 = serializer.Deserialize<Mall>(json);
            Assert.AreEqual(mall.Name, mall2.Name);
        }