Beispiel #1
0
        public static void TestCase14()
        {
            TestBaseConfig.Seed = 1;
            Int32Class a = ShiboSerializer.Initialize <Int32Class>(53456158);

            byte[]     bytes = ShiboSerializer.BinarySerialize(a);
            Int32Class b     = ShiboSerializer.BinaryDeserialize <Int32Class>(bytes);

            //Console.WriteLine(ShiboComparer.Compare<List<string>>(a, b));
            Console.WriteLine(JsonConvert.SerializeObject(a) == JsonConvert.SerializeObject(b));

            ObjectWriter bf = new ObjectWriter(50);
            Stopwatch    w  = Stopwatch.StartNew();

            for (int i = 0; i < 1000000; i++)
            {
                //bytes = ShiboSerializer.BinarySerialize(a);
                //b = ShiboSerializer.BinaryDeserialize<List<string>>(bytes);
                bf.Reset();
                ShiboSerializer.BinarySerialize(bf, a);
            }
            w.Stop();
            Console.WriteLine(w.ElapsedMilliseconds);
            //Console.WriteLine(JsonConvert.SerializeObject(b.Count));
        }
        public static void TestCase6()
        {
            TestBaseConfig.Seed = 1;
            StringListClass a = ShiboSerializer.Initialize <StringListClass>(123456);
            //a.V1 = new uint[]{};
            StringListClass c    = null;
            string          json = ShiboSerializer.Serialize(a);

            c = ShiboSerializer.Deserialize <StringListClass>(json);
            c = JsonConvert.DeserializeObject <StringListClass>(json);
            //byte[] bytes = ShiboSerializer.BinSerialize(a);
            Console.WriteLine(JsonConvert.SerializeObject(a) == json);
            //Test(a);

            Stopwatch w = Stopwatch.StartNew();

            for (int i = 0; i < 100000; i++)
            {
                //json = JsonConvert.SerializeObject(a);
                //json = ShiboSerializer.Serialize(a);
                c = ShiboSerializer.Deserialize <StringListClass>(json);
                //c = JsonConvert.DeserializeObject<StringListClass>(json);
                //c = ShiboSerializer.BinDeserialize<Int32ArrayClass>(bytes);
            }
            w.Stop();
            Console.WriteLine(w.ElapsedMilliseconds);
            Console.WriteLine(JsonConvert.SerializeObject(a) == JsonConvert.SerializeObject(c));
        }
Beispiel #3
0
        public static void TestCase1()
        {
            //Guid guid = new Guid("e92b8e30-a6e5-41f6-a6b9-188230a23dd2");
            //byte[] buffer = guid.ToByteArray();
            //Console.WriteLine(BitConverter.ToString(buffer));
            Dictionary <int, string> v = new Dictionary <int, string>();

            v.Add(1, null);

            TestBaseConfig.Seed = 1;
            Int32Class a  = ShiboSerializer.Initialize <Int32Class>();// Int32Class.Init();
            string     s1 = ShiboSerializer.Serialize(a);
            string     s2 = null;

            byte[] buffer = ShiboSerializer.BinarySerialize(a);
            a  = ShiboSerializer.BinaryDeserialize <Int32Class>(buffer);
            s2 = ShiboSerializer.Serialize(a);
            Console.WriteLine(BitConverter.ToString(buffer));
            Console.WriteLine(s1 == s2);
            //Console.ReadLine();
            Test(a);

            //Int32FieldClass a = Int32FieldClass.Init();
            //byte[] buffer = ShiboSerializer.BinSerialize(a);
            ////byte[] b = new byte[400];
            ////Buffer.BlockCopy(buffer, 0, b, 0, 4);
            //a = ShiboSerializer.BinDeserialize<Int32FieldClass>(buffer);
            //Console.WriteLine(BitConverter.ToString(buffer));
            //Console.WriteLine(ShiboSerializer.Serialize(a));
            Console.ReadLine();
        }
        public static void RunIntObjSeries()
        {
            //Random rd = new Random(1);
            var rd     = new Random(1);
            var floats = new List <IXYV>(100000);

            for (int i = 0; i < floats.Capacity; i++)
            {
                //floats.Add(new IXYV() { X = rd.Next() >> 15, Y = rd.Next() >> 15, V = rd.Next() >> 15 });
                floats.Add(new IXYV()
                {
                    X = rd.Next(), Y = rd.Next(), V = rd.Next()
                });
            }
            string s = ShiboSerializer.ToCsv(floats);
            //string s = JsonConvert.SerializeObject(floats);
            Stopwatch w = Stopwatch.StartNew();

            for (int i = 0; i < 10; i++)
            {
                //s = JsonConvert.SerializeObject(floats);
                s = ShiboSerializer.ToCsv(floats);
                //CsvHelper.CsvSerializer csv = new CsvHelper.CsvSerializer(null);
                //CsvHelper.CsvWriter w = new CsvHelper.CsvWriter(null);
            }


            w.Stop();
            Console.WriteLine(w.ElapsedMilliseconds + " " + s.Length);
            Console.ReadLine();
        }
        public static void RunCsvListTest()
        {
            //ShiboSerializer.Serialize(os, graph, sets);

            //List<int> v = new List<int>();
            //v.Add(123);
            //v.Add(456);

            //IList<bool> v = new List<bool>();
            //v.Add(true);
            //v.Add(false);

            int n = 100;
            IList <Int32Class> v = new List <Int32Class>(n);

            for (int i = 0; i < n; i++)
            {
                v.Add(ShiboSerializer.Initialize <Int32Class>());
            }
            string csv = ShiboSerializer.ToCsv(v);

            //CsvHelper.CsvWriter c = new CsvHelper.CsvWriter();


            Console.WriteLine(csv);
        }
        public static void TestCase7()
        {
            string path = "bigjson.txt";

            if (File.Exists(path))
            {
                TestBaseConfig.Seed = 1;
                string       json = File.ReadAllText(path);
                ClubJsonCase o    = ShiboSerializer.Initialize <ClubJsonCase>();// ShiboSerializer.Deserialize<ClubJsonCase>(json);
                //ClubJsonCase o1 = JsonConvert.DeserializeObject<ClubJsonCase>(json);
                json = JsonConvert.SerializeObject(o);
                //Console.WriteLine(JsonConvert.SerializeObject(o) == JsonConvert.SerializeObject(o1));
                ClubJsonCase o1 = null;
                o1 = ShiboSerializer.Deserialize <ClubJsonCase>(json);
                o1 = JsonConvert.DeserializeObject <ClubJsonCase>(json);

                //Result o2 = null;

                Stopwatch w = Stopwatch.StartNew();
                for (int i = 0; i < 100; i++)
                {
                    //o1 = ShiboSerializer.Deserialize<ClubJsonCase>(json);
                    //o1 = JsonConvert.DeserializeObject<ClubJsonCase>(json);

                    //o2 = ShiboSerializer.Deserialize<Result>(json);
                    //o2 = JsonConvert.DeserializeObject<Result>(json);
                }
                w.Stop();
                Console.WriteLine(w.ElapsedMilliseconds);
                Console.WriteLine(JsonConvert.SerializeObject(o) == JsonConvert.SerializeObject(o1));
                //Console.WriteLine(JsonConvert.SerializeObject(o1.Result) == JsonConvert.SerializeObject(o2));
            }
        }
Beispiel #7
0
 public void Setup()
 {
     data = new Int32Class[Size];
     for (int i = 0; i < data.Length; i++)
     {
         data[i] = ShiboSerializer.Initialize <Int32Class>();
     }
 }
        public void TestAllBaseType()
        {
            var data = new TestAllBaseType[100];

            for (int i = 0; i < data.Length; i++)
            {
                data[i] = ShiboSerializer.Initialize <TestAllBaseType>();
            }
            var ret            = ShiboSerializer.ToColumns(data);
            var boolValue      = new bool[data.Length];
            var boolValueFalse = new bool[data.Length];
            var byteValue      = new byte[data.Length];
            var sbyteValue     = new sbyte[data.Length];
            var charValue      = new char[data.Length];
            var shortValue     = new short[data.Length];
            var ushortValue    = new ushort[data.Length];
            var intValue       = new int[data.Length];
            var uintValue      = new uint[data.Length];
            var longValue      = new long[data.Length];
            var ulongValue     = new ulong[data.Length];
            var floatValue     = new float[data.Length];
            var doubleValue    = new double[data.Length];
            var decimalValue   = new decimal[data.Length];

            for (int i = 0; i < data.Length; i++)
            {
                boolValue[i]      = data[i].boolValue;
                boolValueFalse[i] = data[i].boolValueFalse;
                byteValue[i]      = data[i].byteValue;
                sbyteValue[i]     = data[i].sbyteValue;
                charValue[i]      = data[i].charValue;
                shortValue[i]     = data[i].shortValue;
                ushortValue[i]    = data[i].ushortValue;
                intValue[i]       = data[i].intValue;
                uintValue[i]      = data[i].uintValue;
                longValue[i]      = data[i].longValue;
                ulongValue[i]     = data[i].ulongValue;
                floatValue[i]     = data[i].floatValue;
                doubleValue[i]    = data[i].doubleValue;
                decimalValue[i]   = data[i].decimalValue;
            }
            Assert.AreEqual(Json(ret[0].Value), Json(boolValue));
            Assert.AreEqual(Json(ret[1].Value), Json(boolValueFalse));
            Assert.AreEqual(Json(ret[2].Value), Json(byteValue));
            Assert.AreEqual(Json(ret[3].Value), Json(sbyteValue));
            Assert.AreEqual(Json(ret[4].Value), Json(charValue));
            Assert.AreEqual(Json(ret[5].Value), Json(shortValue));
            Assert.AreEqual(Json(ret[6].Value), Json(ushortValue));
            Assert.AreEqual(Json(ret[7].Value), Json(intValue));
            Assert.AreEqual(Json(ret[8].Value), Json(uintValue));
            Assert.AreEqual(Json(ret[9].Value), Json(longValue));
            Assert.AreEqual(Json(ret[10].Value), Json(ulongValue));
            Assert.AreEqual(Json(ret[11].Value), Json(floatValue));
            Assert.AreEqual(Json(ret[12].Value), Json(doubleValue));
            Assert.AreEqual(Json(ret[13].Value), Json(decimalValue));
        }
        public void UseEmit()
        {
            long sum = 0;

            for (int i = 0; i < N; i++)
            {
                var ret = ShiboSerializer.ToColumns(dataInt8);
                sum += ret.Length;
            }
        }
Beispiel #10
0
        public void FastToCsv()
        {
            long sum = 0;

            for (int i = 0; i < N; i++)
            {
                var csv = ShiboSerializer.ToCsv(data);
                sum += csv.Length;
            }
        }
Beispiel #11
0
        public static void MultipleTypeMethodTest()
        {
            PrimitiveTypeClass v    = ShiboSerializer.Initialize <PrimitiveTypeClass>(4578424);
            string             json = ShiboSerializer.Serialize(v);

            byte[] bytes = ShiboSerializer.BinarySerialize(v);

            Console.WriteLine(json == JsonConvert.SerializeObject(v));
            v = ShiboSerializer.BinaryDeserialize <PrimitiveTypeClass>(bytes);
            Console.WriteLine(json == JsonConvert.SerializeObject(v));
        }
Beispiel #12
0
 public static void TestCase8()
 {
     TestBaseConfig.Seed = 1;
     MixClass a = ShiboSerializer.Initialize <MixClass>(TestBaseConfig.Seed);
     //a.V8 = "sdfdfg";
     //a.V5.V3 = 1;
     MixClass b = ShiboSerializer.Initialize <MixClass>(TestBaseConfig.Seed);
     //b.V8 = "sdfdfg";
     //Assert.AreEqual(
     //Console.WriteLine(ShiboComparer.Compare(a, b));
 }
 public void Setup()
 {
     dataInt8  = new Int8Class[Size];
     dataInt32 = new Int32Class[Size];
     dataInt64 = new Int64Class[Size];
     for (int i = 0; i < dataInt8.Length; i++)
     {
         dataInt8[i]  = ShiboSerializer.Initialize <Int8Class>();
         dataInt32[i] = ShiboSerializer.Initialize <Int32Class>();
         dataInt64[i] = ShiboSerializer.Initialize <Int64Class>();
     }
 }
Beispiel #14
0
        public void TestInt8()
        {
            var data = new Int8Class[100];

            for (int i = 0; i < data.Length; i++)
            {
                data[i] = ShiboSerializer.Initialize <Int8Class>();
            }
            var expected = ServiceStack.Text.CsvSerializer.SerializeToCsv(data);
            var actual   = ShiboSerializer.ToCsv(data);

            Assert.AreEqual(expected, actual);
        }
Beispiel #15
0
        public void TestInt32Bytes()
        {
            var data = new Int32Class[10];

            for (int i = 0; i < data.Length; i++)
            {
                data[i] = ShiboSerializer.Initialize <Int32Class>();
            }
            var expected = ServiceStack.Text.CsvSerializer.SerializeToCsv(data);
            var actual   = Encoding.UTF8.GetString(ShiboSerializer.ToCsvUtf8(data));

            Assert.AreEqual(expected, actual);
        }
        public static void TestCase1()
        {
            string path = "bigjson.txt";

            if (File.Exists(path))
            {
                string       json = File.ReadAllText(path);
                ClubJsonCase o    = ShiboSerializer.Deserialize <ClubJsonCase>(json);
                ClubJsonCase o1   = JsonConvert.DeserializeObject <ClubJsonCase>(json);
                Console.WriteLine(JsonConvert.SerializeObject(o) == JsonConvert.SerializeObject(o1));
                //Test(o);
            }
        }
 public MixClass(int seed)
 {
     rd = new Random(seed);
     //V0 = (byte)rd.Next(int.MinValue, int.MaxValue);
     //V1 = (sbyte)rd.Next(int.MinValue, int.MaxValue);
     //V2 = (short)rd.Next(int.MinValue, int.MaxValue);
     //V3 = (ushort)rd.Next(int.MinValue, int.MaxValue);
     V4 = rd.Next(int.MinValue, int.MaxValue);
     V5 = ShiboSerializer.Initialize <Int32Class>(); //Int32Class.Init();
     //V6 = new int[rd.Next(TestBaseConfig.ArrayMinSize, TestBaseConfig.ArrayMaxSize)];
     //for (int i = 0; i < V6.Length; i++)
     //    V6[i] = (int)rd.Next(sbyte.MinValue, sbyte.MaxValue);
     V7 = rd.Next(int.MinValue, int.MaxValue);
 }
Beispiel #18
0
        /// <summary>
        /// 对象数据初始化测试
        /// </summary>
        public static void TestCase7()
        {
            TestBaseConfig.Seed = 1;
            MixClass  a = ShiboSerializer.Initialize <MixClass>();
            Stopwatch w = Stopwatch.StartNew();

            for (int i = 0; i < 1000000; i++)
            {
                a = ShiboSerializer.Initialize <MixClass>();
            }
            w.Stop();
            Console.WriteLine(w.ElapsedMilliseconds);
            Console.WriteLine(JsonConvert.SerializeObject(a));
        }
Beispiel #19
0
        public static void Run()
        {
            NormalClass n = new NormalClass();

            n.X = 12;
            n.Y = "78";
            n.Z = 4.6;
            n.V = 'c';
            //string s = SerializeCodeGenerator.ToJson(n);
            //string s = ToJson(n);
            //string s = ToJsonFunc(n);
            string s = ShiboSerializer.ToJson(n);

            Console.WriteLine(s);
            //SerializeCodeGenerator.CreateCodeDll1();
        }
Beispiel #20
0
        public static void Run()
        {
            var Size = 10;
            var data = new Int8Class[Size];

            for (int i = 0; i < data.Length; i++)
            {
                data[i] = ShiboSerializer.Initialize <Int8Class>();
            }


            var result = ConvertInt8Class(data);
            var str    = Encoding.UTF8.GetString(result);

            Console.WriteLine(result);
        }
Beispiel #21
0
        public static void TestCase6()
        {
            TestBaseConfig.Seed = 1;
            ArraySegmentClass a = new ArraySegmentClass();

            byte[]    buffer = ShiboSerializer.BinarySerialize(a);
            Stopwatch w      = Stopwatch.StartNew();

            for (int i = 0; i < 1000000; i++)
            {
                buffer = ShiboSerializer.BinarySerialize(a);
            }
            w.Stop();
            Console.WriteLine(w.ElapsedMilliseconds);
            Console.WriteLine(buffer);
            Console.WriteLine(JsonConvert.SerializeObject(a));
        }
Beispiel #22
0
        public static void TestCase4()
        {
            TestBaseConfig.Seed = 1;
            MixClass a = MixClass.Init();

            byte[]    buffer = ShiboSerializer.BinarySerialize(a);
            MixClass  b      = ShiboSerializer.BinaryDeserialize <MixClass>(buffer);
            Stopwatch w      = Stopwatch.StartNew();

            for (int i = 0; i < 1000000; i++)
            {
                buffer = ShiboSerializer.BinarySerialize(a);
                //b = ShiboSerializer.BinDeserialize<MixClass>(buffer);
            }
            w.Stop();
            Console.WriteLine(w.ElapsedMilliseconds);
            Console.WriteLine(JsonConvert.SerializeObject(a) == JsonConvert.SerializeObject(b));
        }
Beispiel #23
0
        public static void TestCase13()
        {
            TestBaseConfig.Seed = 1;
            byte[][] a     = ShiboSerializer.Initialize <byte[][]>(53456158);
            byte[]   bytes = ShiboSerializer.BinarySerialize(a);
            byte[][] b     = ShiboSerializer.BinaryDeserialize <byte[][]>(bytes);
            //Console.WriteLine(ShiboComparer.Compare<List<string>>(a, b));
            Console.WriteLine(JsonConvert.SerializeObject(a) == JsonConvert.SerializeObject(b));

            //Stopwatch w = Stopwatch.StartNew();
            //for (int i = 0; i < 10000; i++)
            //{
            //    //bytes = ShiboSerializer.BinarySerialize(a);
            //    b = ShiboSerializer.BinaryDeserialize<List<string>>(bytes);
            //}
            //w.Stop();
            //Console.WriteLine(w.ElapsedMilliseconds);
            //Console.WriteLine(JsonConvert.SerializeObject(b.Count));
        }
Beispiel #24
0
        /// <summary>
        ///
        /// </summary>
        public static void TestCase10()
        {
            TestBaseConfig.Seed = 1;
            Dictionary <int, bool> a = ShiboSerializer.Initialize <Dictionary <int, bool> >(53456158);

            byte[] bytes             = ShiboSerializer.BinarySerialize(a);
            Dictionary <int, bool> b = ShiboSerializer.BinaryDeserialize <Dictionary <int, bool> >(bytes);

            Stopwatch w = Stopwatch.StartNew();

            for (int i = 0; i < 10000; i++)
            {
                //bytes = ShiboSerializer.BinarySerialize(a);
                b = ShiboSerializer.BinaryDeserialize <Dictionary <int, bool> >(bytes);
            }
            w.Stop();
            Console.WriteLine(w.ElapsedMilliseconds);
            Console.WriteLine(JsonConvert.SerializeObject(b.Count));
        }
        public void TestInt64()
        {
            var data = new Int64Class[100];

            for (int i = 0; i < data.Length; i++)
            {
                data[i] = ShiboSerializer.Initialize <Int64Class>();
            }
            var ret = ShiboSerializer.ToColumns(data);
            var v0s = new long[data.Length];

            for (int i = 0; i < data.Length; i++)
            {
                v0s[i] = data[i].V0;
            }
            var v1 = Csv((long[])ret[0].Value);
            var v2 = Csv(v0s);

            Assert.AreEqual(v1, v2);
        }
        public void TestInt8()
        {
            var data = new Int8Class[100];

            for (int i = 0; i < data.Length; i++)
            {
                data[i] = ShiboSerializer.Initialize <Int8Class>();
            }
            var ret   = ShiboSerializer.ToColumns(data);
            var bytes = new byte[data.Length];

            for (int i = 0; i < data.Length; i++)
            {
                bytes[i] = data[i].V0;
            }
            var v1 = ServiceStack.Text.CsvSerializer.SerializeToCsv((byte[])ret[0].Value);
            var v2 = ServiceStack.Text.CsvSerializer.SerializeToCsv(bytes);

            Assert.AreEqual(v1, v2);
        }
        public void TestInt32()
        {
            var data = new Int32Class[100];

            for (int i = 0; i < data.Length; i++)
            {
                data[i] = ShiboSerializer.Initialize <Int32Class>();
            }
            var ret   = ShiboSerializer.ToColumns(data);
            var bytes = new int[data.Length];

            for (int i = 0; i < data.Length; i++)
            {
                bytes[i] = data[i].V0;
            }
            var v1 = Csv((int[])ret[0].Value);
            var v2 = Csv(bytes);

            Assert.AreEqual(v1, v2);
        }
        public static TestResult Test2(object graph)
        {
            //ShiboSerializer.Serialize(os, graph, sets);

            //List<int> v = new List<int>();
            //v.Add(123);
            //v.Add(456);

            var v = new List <bool>
            {
                true,
                false
            };

            //Int32Class v = Int32Class.Init();
            string csv = ShiboSerializer.ToCsv(v);

            Console.WriteLine(csv);
            return(null);
        }
        public static void TestCase8()
        {
            string       path = "bigjson.txt";
            string       json = File.ReadAllText(path);
            ClubJsonCase o    = JsonConvert.DeserializeObject <ClubJsonCase>(json);
            //string s = ShiboSerializer.Serialize(o);
            JsonString s   = ShiboSerializer.SerializeToBuffer(o);
            int        len = 0;
            Stopwatch  w   = Stopwatch.StartNew();

            for (int i = 0; i < 100; i++)
            {
                //s = ShiboSerializer.Serialize(o);
                //len += s.Length;

                s    = ShiboSerializer.SerializeToBuffer(o);
                len += s.Position;
            }
            w.Stop();
            Console.WriteLine(w.ElapsedMilliseconds + " " + len);
        }
        public static void TestCase4()
        {
            TestBaseConfig.Seed = 1;
            MixClass a    = MixClass.Init();
            string   json = ShiboSerializer.Serialize(a);
            MixClass b    = ShiboSerializer.Deserialize <MixClass>(json);

            //Test(a);

            Stopwatch w = Stopwatch.StartNew();

            for (int i = 0; i < 1000000; i++)
            {
                //JsonConvert.SerializeObject(a);
                //ShiboSerializer.Serialize(a);
                b = ShiboSerializer.Deserialize <MixClass>(json);
                //b = JsonConvert.DeserializeObject<MixClass>(json);
            }
            w.Stop();
            Console.WriteLine(w.ElapsedMilliseconds);
            Console.WriteLine(JsonConvert.SerializeObject(a) == JsonConvert.SerializeObject(b));
        }