예제 #1
0
        private static void fastjson_serialize()
        {
            Console.WriteLine();
            Console.Write("fastjson serialize");
            colclass      c         = CreateObject();
            List <double> times     = new List <double>();
            var           stopwatch = new Stopwatch();

            for (int pp = 0; pp < tcount; pp++)
            {
                string jsonText = null;
                stopwatch.Restart();
                for (int i = 0; i < count; i++)
                {
                    jsonText = fastJSON.JSON.ToJSON(c);
                }
                stopwatch.Stop();
                if (pp > 0)
                {
                    times.Add(stopwatch.ElapsedMilliseconds);
                }
                Console.Write("\t" + stopwatch.ElapsedMilliseconds);
            }
            Console.WriteLine($"\r\nMin: {times.Min()} Max: {times.Max()} Average: {times.Average()}");
        }
예제 #2
0
        private static void bin_deserialize()
        {
            Console.WriteLine();
            Console.Write("bin deserialize");
            colclass c         = CreateObject();
            var      stopwatch = new Stopwatch();

            for (int pp = 0; pp < tcount; pp++)
            {
                BinaryFormatter bf = new BinaryFormatter();
                MemoryStream    ms = new MemoryStream();
                colclass        deserializedStore = null;
                stopwatch.Restart();
                bf.Serialize(ms, c);
                //Console.WriteLine(" size = " +ms.Length);
                for (int i = 0; i < count; i++)
                {
                    stopwatch.Stop();                     // we stop then resume the stopwatch here so we don't factor in Seek()'s execution
                    ms.Seek(0L, SeekOrigin.Begin);
                    stopwatch.Start();
                    deserializedStore = (colclass)bf.Deserialize(ms);
                }
                stopwatch.Stop();
                Console.Write("\t" + stopwatch.ElapsedMilliseconds);
            }
        }
예제 #3
0
        private static void fastjson_deserialize()
        {
            Console.Write("fastjson deserialize");
            colclass c = CreateObject();

            var stopwatch = new Stopwatch();

            for (int pp = 0; pp < tcount; pp++)
            {
                colclass deserializedStore;
                string   jsonText = null;

                stopwatch.Restart();
                jsonText = fastJSON.JSON.ToJSON(c, new fastJSON.JSONParameters()
                {
                    SerializeNullValues = false
                });
                //Console.WriteLine(" size = " + jsonText.Length);
                for (int i = 0; i < count; i++)
                {
                    deserializedStore = fastJSON.JSON.ToObject <colclass>(jsonText);
                }
                stopwatch.Stop();
                Console.Write("\t" + stopwatch.ElapsedMilliseconds);
            }
            Console.WriteLine();
        }
예제 #4
0
        //private static string pser(object data)
        //{
        //    System.Drawing.Point p = (System.Drawing.Point)data;
        //    return p.X.ToString() + "," + p.Y.ToString();
        //}

        //private static object pdes(string data)
        //{
        //    string[] ss = data.Split(',');

        //    return new System.Drawing.Point(
        //        int.Parse(ss[0]),
        //        int.Parse(ss[1])
        //        );
        //}

        //private static string tsser(object data)
        //{
        //    return ((TimeSpan)data).Ticks.ToString();
        //}

        //private static object tsdes(string data)
        //{
        //    return new TimeSpan(long.Parse(data));
        //}

        public static colclass CreateObject()
        {
            var c = new colclass();

            c.booleanValue    = true;
            c.ordinaryDecimal = 3;

            if (exotic)
            {
                c.nullableGuid     = Guid.NewGuid();
                c.hash             = new Hashtable();
                c.bytes            = new byte[1024];
                c.stringDictionary = new Dictionary <string, baseclass>();
                c.objectDictionary = new Dictionary <baseclass, baseclass>();
                c.intDictionary    = new Dictionary <int, baseclass>();
                c.nullableDouble   = 100.003;

                if (dsser)
                {
                    c.dataset = ds;
                }
                c.nullableDecimal = 3.14M;

                c.hash.Add(new class1("0", "hello", Guid.NewGuid()), new class2("1", "code", "desc"));
                c.hash.Add(new class2("0", "hello", "pppp"), new class1("1", "code", Guid.NewGuid()));

                c.stringDictionary.Add("name1", new class2("1", "code", "desc"));
                c.stringDictionary.Add("name2", new class1("1", "code", Guid.NewGuid()));

                c.intDictionary.Add(1, new class2("1", "code", "desc"));
                c.intDictionary.Add(2, new class1("1", "code", Guid.NewGuid()));

                c.objectDictionary.Add(new class1("0", "hello", Guid.NewGuid()), new class2("1", "code", "desc"));
                c.objectDictionary.Add(new class2("0", "hello", "pppp"), new class1("1", "code", Guid.NewGuid()));

                c.arrayType    = new baseclass[2];
                c.arrayType[0] = new class1();
                c.arrayType[1] = new class2();
            }


            c.items.Add(new class1("1", "1", Guid.NewGuid()));
            c.items.Add(new class2("2", "2", "desc1"));
            c.items.Add(new class1("3", "3", Guid.NewGuid()));
            c.items.Add(new class2("4", "4", "desc2"));

            c.laststring = "" + DateTime.Now;

            return(c);
        }
예제 #5
0
파일: Program.cs 프로젝트: mgholam/fastJSON
        //private static string pser(object data)
        //{
        //    System.Drawing.Point p = (System.Drawing.Point)data;
        //    return p.X.ToString() + "," + p.Y.ToString();
        //}
        //private static object pdes(string data)
        //{
        //    string[] ss = data.Split(',');
        //    return new System.Drawing.Point(
        //        int.Parse(ss[0]),
        //        int.Parse(ss[1])
        //        );
        //}
        //private static string tsser(object data)
        //{
        //    return ((TimeSpan)data).Ticks.ToString();
        //}
        //private static object tsdes(string data)
        //{
        //    return new TimeSpan(long.Parse(data));
        //}
        public static colclass CreateObject()
        {
            var c = new colclass();

            c.booleanValue = true;
            c.ordinaryDecimal = 3;

            if (exotic)
            {
                c.nullableGuid = Guid.NewGuid();
                c.hash = new Hashtable();
                c.bytes = new byte[1024];
                c.stringDictionary = new Dictionary<string, baseclass>();
                c.objectDictionary = new Dictionary<baseclass, baseclass>();
                c.intDictionary = new Dictionary<int, baseclass>();
                c.nullableDouble = 100.003;

                if (dsser)
                    c.dataset = ds;
                c.nullableDecimal = 3.14M;

                c.hash.Add(new class1("0", "hello", Guid.NewGuid()), new class2("1", "code", "desc"));
                c.hash.Add(new class2("0", "hello", "pppp"), new class1("1", "code", Guid.NewGuid()));

                c.stringDictionary.Add("name1", new class2("1", "code", "desc"));
                c.stringDictionary.Add("name2", new class1("1", "code", Guid.NewGuid()));

                c.intDictionary.Add(1, new class2("1", "code", "desc"));
                c.intDictionary.Add(2, new class1("1", "code", Guid.NewGuid()));

                c.objectDictionary.Add(new class1("0", "hello", Guid.NewGuid()), new class2("1", "code", "desc"));
                c.objectDictionary.Add(new class2("0", "hello", "pppp"), new class1("1", "code", Guid.NewGuid()));

                c.arrayType = new baseclass[2];
                c.arrayType[0] = new class1();
                c.arrayType[1] = new class2();
            }

            c.items.Add(new class1("1", "1", Guid.NewGuid()));
            c.items.Add(new class2("2", "2", "desc1"));
            c.items.Add(new class1("3", "3", Guid.NewGuid()));
            c.items.Add(new class2("4", "4", "desc2"));

            c.laststring = "" + DateTime.Now;

            return c;
        }
예제 #6
0
        private static void fastjson_serialize()
        {
            Console.WriteLine();
            Console.Write("fastbinaryjson serialize");
            colclass c = CreateObject();

            for (int pp = 0; pp < tcount; pp++)
            {
                DateTime st       = DateTime.Now;
                byte[]   jsonText = null;
                for (int i = 0; i < count; i++)
                {
                    jsonText = fastBinaryJSON.BJSON.ToBJSON(c);
                }
                Console.Write("\t" + DateTime.Now.Subtract(st).TotalMilliseconds);
            }
        }
예제 #7
0
        private static void bin_serialize()
        {
            Console.Write("\r\nbin serialize");
            colclass c = CreateObject();

            for (int pp = 0; pp < tcount; pp++)
            {
                DateTime        st = DateTime.Now;
                BinaryFormatter bf = new BinaryFormatter();
                MemoryStream    ms = new MemoryStream();
                for (int i = 0; i < count; i++)
                {
                    ms = new MemoryStream();
                    bf.Serialize(ms, c);
                }
                Console.Write("\t" + DateTime.Now.Subtract(st).TotalMilliseconds);
            }
        }
예제 #8
0
        private static void fastjson_serialize()
        {
            Console.WriteLine();
            Console.Write("fastjson serialize");
            colclass c         = CreateObject();
            var      stopwatch = new Stopwatch();

            for (int pp = 0; pp < tcount; pp++)
            {
                string jsonText = null;
                stopwatch.Restart();
                for (int i = 0; i < count; i++)
                {
                    jsonText = fastJSON.JSON.ToJSON(c);
                }
                stopwatch.Stop();
                Console.Write("\t" + stopwatch.ElapsedMilliseconds);
            }
        }
예제 #9
0
        private static void fastjson_deserialize()
        {
            Console.WriteLine();
            Console.Write("fastbinaryjson deserialize");
            colclass c = CreateObject();

            for (int pp = 0; pp < tcount; pp++)
            {
                DateTime st = DateTime.Now;
                colclass deserializedStore;
                byte[]   jsonText = null;

                jsonText = fastBinaryJSON.BJSON.ToBJSON(c);
                //Console.WriteLine(" size = " + jsonText.Length);
                for (int i = 0; i < count; i++)
                {
                    deserializedStore = (colclass)fastBinaryJSON.BJSON.ToObject(jsonText);
                }
                Console.Write("\t" + DateTime.Now.Subtract(st).TotalMilliseconds);
            }
        }
예제 #10
0
        private static void bin_serialize()
        {
            Console.Write("\r\nbin serialize");
            colclass c         = CreateObject();
            var      stopwatch = new Stopwatch();

            for (int pp = 0; pp < tcount; pp++)
            {
                BinaryFormatter bf = new BinaryFormatter();
                MemoryStream    ms = new MemoryStream();
                stopwatch.Restart();
                for (int i = 0; i < count; i++)
                {
                    stopwatch.Stop();                     // we stop then resume the stop watch here so we don't factor in the MemoryStream()'s execution
                    ms = new MemoryStream();
                    stopwatch.Start();
                    bf.Serialize(ms, c);
                }
                stopwatch.Stop();
                Console.Write("\t" + stopwatch.ElapsedMilliseconds);
            }
        }
예제 #11
0
        private static void bin_deserialize()
        {
            Console.WriteLine();
            Console.Write("bin deserialize");
            colclass c = CreateObject();

            for (int pp = 0; pp < tcount; pp++)
            {
                DateTime        st = DateTime.Now;
                BinaryFormatter bf = new BinaryFormatter();
                MemoryStream    ms = new MemoryStream();
                bf.Serialize(ms, c);
                colclass deserializedStore = null;
                //Console.WriteLine(" size = " +ms.Length);
                for (int i = 0; i < count; i++)
                {
                    ms.Seek(0L, SeekOrigin.Begin);
                    deserializedStore = (colclass)bf.Deserialize(ms);
                }
                Console.Write("\t" + DateTime.Now.Subtract(st).TotalMilliseconds);
            }
        }