Ejemplo n.º 1
0
    private static colclass CreateBigdata()
    {
        colclass c = new colclass();
        Random   r = new Random((int)DateTime.Now.Ticks);

        for (int i = 0; i < 2 * thousandtimes * thousandtimes; i++)
        {
            c.items.Add(new class1(r.Next().ToString(), r.Next().ToString(), Guid.NewGuid()));
        }
        return(c);
    }
Ejemplo n.º 2
0
        public static colclass CreateObject()
        {
            var c = new colclass();

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

            if (exotic)
            {
                c.nullableGuid = Guid.NewGuid();
#if !SILVERLIGHT
                c.hash = new Hashtable();
                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()));
                if (dsser)
                {
                    c.dataset = ds;
                }
#endif
                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;


                c.nullableDecimal = 3.14M;



                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);
        }
Ejemplo n.º 3
0
    public static void exotic_serialize()
    {
        Console.WriteLine();
        Console.Write("fastbinaryjson serialize");
        colclass c         = CreateObject(true, true);
        var      stopwatch = new Stopwatch();

        for (int pp = 0; pp < fivetimes; pp++)
        {
            byte[] jsonText = null;
            stopwatch.Restart();
            for (int i = 0; i < thousandtimes; i++)
            {
                jsonText = BJSON.ToBJSON(c);
            }
            stopwatch.Stop();
            Console.Write("\t" + stopwatch.ElapsedMilliseconds);
        }
    }
Ejemplo n.º 4
0
        public static void Speed_Test_Serialize()
        {
            Console.Write("fastjson serialize");
            //fastJSON.JSON.Instance.Parameters.UsingGlobalTypes = false;
            colclass c = CreateObject();
            double   t = 0;

            for (int pp = 0; pp < tcount; pp++)
            {
                DateTime st       = DateTime.Now;
                string   jsonText = null;
                for (int i = 0; i < count; i++)
                {
                    jsonText = fastJSON.JSON.Instance.ToJSON(c);
                }
                t += DateTime.Now.Subtract(st).TotalMilliseconds;
                Console.Write("\t" + DateTime.Now.Subtract(st).TotalMilliseconds);
            }
            Console.WriteLine("\tAVG = " + t / tcount);
        }
Ejemplo n.º 5
0
    public static void Speed_Test_Serialize()
    {
        Console.Write("fastbinaryjson serialize");
        //fastBinaryJSON.BJSON.Parameters.UsingGlobalTypes = false;
        colclass c = CreateObject(false, false);
        double   t = 0;

        for (int pp = 0; pp < fivetimes; pp++)
        {
            DateTime st       = DateTime.Now;
            byte[]   jsonText = null;
            for (int i = 0; i < thousandtimes; i++)
            {
                jsonText = BJSON.ToBJSON(c);
            }
            t += DateTime.Now.Subtract(st).TotalMilliseconds;
            Console.Write("\t" + DateTime.Now.Subtract(st).TotalMilliseconds);
        }
        Console.WriteLine("\tAVG = " + t / fivetimes);
    }
Ejemplo n.º 6
0
        public static void Speed_Test_Deserialize()
        {
            Console.Write("fastjson deserialize");
            colclass c = CreateObject();
            double   t = 0;

            for (int pp = 0; pp < tcount; pp++)
            {
                DateTime st = DateTime.Now;
                colclass deserializedStore;
                string   jsonText = fastJSON.JSON.Instance.ToJSON(c);
                //Console.WriteLine(" size = " + jsonText.Length);
                for (int i = 0; i < count; i++)
                {
                    deserializedStore = (colclass)fastJSON.JSON.Instance.ToObject(jsonText);
                }
                t += DateTime.Now.Subtract(st).TotalMilliseconds;
                Console.Write("\t" + DateTime.Now.Subtract(st).TotalMilliseconds);
            }
            Console.WriteLine("\tAVG = " + t / tcount);
        }
Ejemplo n.º 7
0
        public static void Speed_Test_Deserialize()
        {
            Console.Write("fastbinaryjson deserialize");
            colclass c = CreateObject();
            double   t = 0;

            for (int pp = 0; pp < tcount; pp++)
            {
                DateTime st = DateTime.Now;
                colclass deserializedStore;
                byte[]   jsonText = fastBinaryJSON.BJSON.ToBJSON(c);
                for (int i = 0; i < count; i++)
                {
                    deserializedStore = fastBinaryJSON.BJSON.ToObject <colclass>(jsonText, new BJSONParameters {
                        ParametricConstructorOverride = true
                    });
                }
                t += DateTime.Now.Subtract(st).TotalMilliseconds;
                Console.Write("\t" + DateTime.Now.Subtract(st).TotalMilliseconds);
            }
            Console.WriteLine("\tAVG = " + t / tcount);
        }
Ejemplo n.º 8
0
    public static void BigData()
    {
        Console.WriteLine();
        Console.Write("fastbinaryjson bigdata serialize");
        colclass c = CreateBigdata();

        Console.WriteLine("\r\ntest obj created");
        var stopwatch = new Stopwatch();

        for (int pp = 0; pp < fivetimes; pp++)
        {
            byte[] jsonText = null;
            stopwatch.Restart();

            jsonText = BJSON.ToBJSON(c);

            stopwatch.Stop();
            Console.Write("\t" + stopwatch.ElapsedMilliseconds + "ms");
            Console.Write("\tcount = " + c.items.Count);
            Console.WriteLine("\tsize = " + jsonText.Length.ToString("#,#"));
        }
        GC.Collect();
    }
Ejemplo n.º 9
0
    public static void exotic_deserialize()
    {
        Console.WriteLine();
        Console.Write("fastbinaryjson deserialize");
        colclass c         = CreateObject(true, true);
        var      stopwatch = new Stopwatch();

        for (int pp = 0; pp < fivetimes; pp++)
        {
            colclass deserializedStore;
            byte[]   jsonText = null;

            stopwatch.Restart();
            jsonText = BJSON.ToBJSON(c);
            //Console.WriteLine(" size = " + jsonText.Length);
            for (int i = 0; i < thousandtimes; i++)
            {
                deserializedStore = (colclass)BJSON.ToObject(jsonText);
            }
            stopwatch.Stop();
            Console.Write("\t" + stopwatch.ElapsedMilliseconds);
        }
    }
Ejemplo n.º 10
0
        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;
        }