public void TestLateBoundSerialization()
        {
            DummyPersistanceObject foo = new DummyPersistanceObject()
            {
                Bar1 = 111, Bar2 = "hello"
            };
            DummyPersistanceObject foo2;

            using (MemoryStream ms = new MemoryStream()) {
                Serializer.Serialize(ms, foo);
                ms.Position = 0;
                foo2        = Serializer.Deserialize <DummyPersistanceObject>(ms);
            }
            Assert.AreEqual(foo, foo2);
        }
        public void TestSerializer()
        {
            DummyPersistanceObject foo = new DummyPersistanceObject()
            {
                Bar1 = 111, Bar2 = "hello"
            };
            DummyPersistanceObject foo2;

            using (MemoryStream ms = new MemoryStream()) {
                GenericSerializer <DummyPersistanceObject> .Serialize(foo, ms);

                ms.Position = 0;
                foo2        = GenericSerializer <DummyPersistanceObject> .Deserialize(ms);
            }
            Assert.AreEqual(foo, foo2);
        }
        public void BenchmarkPerformance()
        {
            List <DummyPersistanceObject> list = new List <DummyPersistanceObject>();

            for (int i = 0; i < 100000; i++)
            {
                list.Add(new DummyPersistanceObject()
                {
                    Bar1 = i, Bar2 = "hello"
                });
            }

            TimeAction("Standard serialization", () =>
            {
                using (MemoryStream ms = new MemoryStream()) {
                    BinaryFormatter bf = new BinaryFormatter();
                    bf.Serialize(ms, list);
                    ms.Position = 0;
                    list        = new List <DummyPersistanceObject>();
                    list        = (List <DummyPersistanceObject>)bf.Deserialize(ms);
                }
            });

            GC.Collect();

            TimeAction("Manual Serialization", () =>
            {
                using (MemoryStream ms = new MemoryStream()) {
                    BinaryWriter bw = new BinaryWriter(ms);
                    foreach (var foo in list)
                    {
                        foo.Write(bw);
                    }
                    ms.Position         = 0;
                    BinaryReader reader = new BinaryReader(ms);
                    list = new List <DummyPersistanceObject>();
                    for (int i = 0; i < 100000; i++)
                    {
                        list.Add(DummyPersistanceObject.Read(reader));
                    }
                }
            });

            GC.Collect();

            TimeAction("Custom Serializer", () =>
            {
                using (MemoryStream ms = new MemoryStream()) {
                    foreach (var foo in list)
                    {
                        Serializer.Serialize(ms, foo);
                    }

                    ms.Position = 0;

                    list = new List <DummyPersistanceObject>();
                    for (int i = 0; i < 100000; i++)
                    {
                        list.Add(Serializer.Deserialize <DummyPersistanceObject>(ms));
                    }
                }
            });
        }
Exemplo n.º 4
0
 public void TestSerializer()
 {
     DummyPersistanceObject foo = new DummyPersistanceObject() { Bar1 = 111, Bar2 = "hello" };
     DummyPersistanceObject foo2;
     using (MemoryStream ms = new MemoryStream()) {
         GenericSerializer<DummyPersistanceObject>.Serialize(foo, ms);
         ms.Position = 0;
         foo2 = GenericSerializer<DummyPersistanceObject>.Deserialize(ms);
     }
     Assert.AreEqual(foo, foo2);
 }
Exemplo n.º 5
0
 public void TestLateBoundSerialization()
 {
     DummyPersistanceObject foo = new DummyPersistanceObject() { Bar1 = 111, Bar2 = "hello" };
     DummyPersistanceObject foo2;
     using (MemoryStream ms = new MemoryStream()) {
         Serializer.Serialize(ms, foo);
         ms.Position = 0;
         foo2 = Serializer.Deserialize<DummyPersistanceObject>(ms);
     }
     Assert.AreEqual(foo, foo2);
 }