Esempio n. 1
0
 public RegularFragment SomeMethod1(RegularFragment value)
 {
     return(new RegularFragment {
         Foo = value.Foo * 2,
         Bar = value.Bar * 2
     });
 }
Esempio n. 2
0
        public void SmallPayload()
        {
            AppDomain app = AppDomain.CreateDomain("Isolated", null,
                                                   AppDomain.CurrentDomain.BaseDirectory,
                                                   AppDomain.CurrentDomain.RelativeSearchPath, false);

            try
            {
                // create a server and two identical messages
                Server local          = new Server(),
                       remote         = (Server)app.CreateInstanceAndUnwrap(typeof(Server).Assembly.FullName, typeof(Server).FullName);
                RegularFragment frag1 = new RegularFragment {
                    Foo = 27, Bar = 123.45F
                };
                Serializer.PrepareSerializer <ProtoFragment>();
                ProtoFragment frag2 = new ProtoFragment {
                    Foo = frag1.Foo, Bar = frag1.Bar
                };
                // verify basic transport
                RegularFragment localFrag1  = local.SomeMethod1(frag1),
                                remoteFrag1 = remote.SomeMethod1(frag1);
                ProtoFragment localFrag2    = local.SomeMethod2(frag2),
                              remoteFrag2   = remote.SomeMethod2(frag2);

                Assert.AreNotSame(localFrag1, remoteFrag1);
                Assert.AreNotSame(localFrag2, remoteFrag2);
                Assert.AreEqual(localFrag1.Foo, remoteFrag1.Foo);
                Assert.AreEqual(localFrag1.Bar, remoteFrag1.Bar);
                Assert.AreEqual(localFrag2.Foo, remoteFrag2.Foo);
                Assert.AreEqual(localFrag2.Bar, remoteFrag2.Bar);
                Assert.AreEqual(localFrag1.Foo, localFrag2.Foo);
                Assert.AreEqual(localFrag1.Bar, localFrag2.Bar);

                const int LOOP = 5000;

                Stopwatch regWatch = Stopwatch.StartNew();
                for (int i = 0; i < LOOP; i++)
                {
                    remoteFrag1 = remote.SomeMethod1(remoteFrag1);
                }
                regWatch.Stop();
                Stopwatch protoWatch = Stopwatch.StartNew();
                for (int i = 0; i < LOOP; i++)
                {
                    remoteFrag2 = remote.SomeMethod2(remoteFrag2);
                }
                protoWatch.Stop();

                Assert.LessOrEqual(3, 5, "just checking...");

                Assert.LessOrEqual(protoWatch.ElapsedMilliseconds, regWatch.ElapsedMilliseconds);
            }
            finally
            {
                AppDomain.Unload(app);
            }
        }
Esempio n. 3
0
        public void TestRawSerializerPerformance()
        {
            RegularFragment frag1 = new RegularFragment {
                Foo = 27, Bar = 123.45F
            };

            ProtoFragment frag2 = new ProtoFragment {
                Foo = frag1.Foo, Bar = frag1.Bar
            };
            Type regular = typeof(RegularFragment), proto = typeof(ProtoFragment);
            var  model = TypeModel.Create();

            model.AutoAddMissingTypes = false;
            model.Add(typeof(ProtoFragment), true);
#if DEBUG
            const int LOOP = 5;
#else
            const int LOOP = 10000;
#endif
            Roundtrip(() => new BinaryFormatter(), LOOP,
                      (ser, dest) => ser.Serialize(dest, frag1), (ser, src) => ser.Deserialize(src));

            Roundtrip("BinaryFormatter via pb-net", () => new BinaryFormatter(), LOOP,
                      (ser, dest) => ser.Serialize(dest, frag2), (ser, src) => ser.Deserialize(src));

            Roundtrip(() => model, LOOP,
                      (ser, dest) => ser.Serialize(dest, frag2), (ser, src) => ser.Deserialize(src, null, proto));

            Roundtrip(() => new XmlSerializer(proto), LOOP,
                      (ser, dest) => ser.Serialize(dest, frag2), (ser, src) => ser.Deserialize(src));

            Roundtrip(() => new DataContractSerializer(regular), LOOP,
                      (ser, dest) => ser.WriteObject(dest, frag1), (ser, src) => ser.ReadObject(src));

            Roundtrip(() => new NetDataContractSerializer(), LOOP,
                      (ser, dest) => ser.Serialize(dest, frag1), (ser, src) => ser.Deserialize(src));

            model.CompileInPlace();
            Roundtrip("CompileInPlace", () => model, LOOP * 50,
                      (ser, dest) => ser.Serialize(dest, frag2), (ser, src) => ser.Deserialize(src, null, proto));

            Roundtrip("Compile", () => model.Compile(), LOOP * 50,
                      (ser, dest) => ser.Serialize(dest, frag2), (ser, src) => ser.Deserialize(src, null, proto));
        }
 public RegularFragment SomeMethod1(RegularFragment value)
 {
     return new RegularFragment {
         Foo = value.Foo * 2,
         Bar = value.Bar * 2
     };
 }
        public void SmallPayload()
        {
            AppDomain app = AppDomain.CreateDomain("Isolated", null,
                AppDomain.CurrentDomain.BaseDirectory,
                AppDomain.CurrentDomain.RelativeSearchPath, false);

            try
            {
                // create a server and two identical messages
                Server local = new Server(),
                    remote = (Server)app.CreateInstanceAndUnwrap(typeof(Server).Assembly.FullName, typeof(Server).FullName);
                RegularFragment frag1 = new RegularFragment { Foo = 27, Bar = 123.45F };
                ProtoFragment frag2 = new ProtoFragment { Foo = frag1.Foo, Bar = frag1.Bar };
                // verify basic transport
                RegularFragment localFrag1 = local.SomeMethod1(frag1),
                    remoteFrag1 = remote.SomeMethod1(frag1);
                ProtoFragment localFrag2 = local.SomeMethod2(frag2),
                    remoteFrag2 = remote.SomeMethod2(frag2);

                Assert.AreEqual(localFrag1.Foo, remoteFrag1.Foo);
                Assert.AreEqual(localFrag1.Bar, remoteFrag1.Bar);
                Assert.AreEqual(localFrag2.Foo, remoteFrag2.Foo);
                Assert.AreEqual(localFrag2.Bar, remoteFrag2.Bar);
                Assert.AreEqual(localFrag1.Foo, localFrag2.Foo);
                Assert.AreEqual(localFrag1.Bar, localFrag2.Bar);

                const int LOOP = 5000;

                Stopwatch regWatch = Stopwatch.StartNew();
                for (int i = 0; i < LOOP; i++)
                {
                    remoteFrag1 = remote.SomeMethod1(remoteFrag1);
                }
                regWatch.Stop();
                Stopwatch protoWatch = Stopwatch.StartNew();
                for (int i = 0; i < LOOP; i++)
                {
                    remoteFrag2 = remote.SomeMethod2(remoteFrag2);
                }
                protoWatch.Stop();

                Assert.LessOrEqual(3, 5, "just checking...");

                Assert.LessOrEqual(protoWatch.ElapsedTicks,
                    (long)(regWatch.ElapsedTicks * 1.00M));
            }
            finally
            {
                AppDomain.Unload(app);
            }
        }