示例#1
0
        private static void bin_deserialize()
        {
            Console.Write("{0,-20}", ".NET Binary");
            var stopwatch = new Stopwatch();

            for (int pp = 0; pp < tcount; pp++)
            {
                BinaryFormatter bf = new BinaryFormatter();
                MemoryStream    ms = new MemoryStream();
                colclass        deserializedStore = null;
                bf.Serialize(ms, sampleData);
                ms.Seek(0L, SeekOrigin.Begin);
                deserializedStore = (colclass)bf.Deserialize(ms);
                stopwatch.Restart();
                //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);
            }
            Console.WriteLine();
        }
示例#2
0
        public static colclass CreateObject(bool exotic, bool dataSet)
        {
            Console.Write("Sample data");
            Console.Write("\tExtensive: " + exotic);
            Console.WriteLine("\tDataset: " + dataSet);
            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;

                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.dataset = dataSet ? ds : null;

            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);
        }
示例#3
0
 private static void SerializationTest(bool exotic)
 {
     Console.Write("Serialization ");
     sampleData = CreateObject(exotic, includeDataset);
     PrintHeader();
     if (includeOthers)
     {
         bin_serialize();
     }
     PowerJson_serialize();
     if (includeOthers)
     {
         JsonNet_serialize();
         ServiceStack_serialize();
     }
     Console.WriteLine();
 }