コード例 #1
0
        static void Generate(ref AddressBook ab, ref NetAddressBook nab)
        {
            ab.List  = new List <Person>();
            nab.List = new List <NetPerson>();
            //Generating structures
            for (int n = 0; n < 5000; n++)
            {
                Person p = new Person();
                p.Name  = "Alice" + n;
                p.Id    = 17532;
                p.Email = "Alice" + n + "@silentobit.com";
                p.Phone = new List <Person.PhoneNumber>();
                ab.List.Add(p);

                NetPerson np = new NetPerson();
                np.Name  = p.Name;
                np.Id    = p.Id;
                np.Email = p.Email;
                np.Phone = new List <NetPerson.NetPhoneNumber>();
                nab.List.Add(np);

                for (int m = 0; m < 1000; m++)
                {
                    Person.PhoneNumber pn = new Person.PhoneNumber();
                    pn.Type   = Person.PhoneType.MOBILE;
                    pn.Number = m.ToString();
                    p.Phone.Add(pn);

                    NetPerson.NetPhoneNumber npn = new NetPerson.NetPhoneNumber();
                    npn.Type   = Person.PhoneType.MOBILE;
                    npn.Number = pn.Number;
                    np.Phone.Add(npn);
                }
            }
        }
コード例 #2
0
ファイル: BenchMark.cs プロジェクト: veintin/sproto-Csharp
        public BenchMark()
        {
            AddressBook address = new AddressBook();

            address.person = new System.Collections.Generic.List <Person> ();

            Person person = new Person();

            person.name = "Alice";
            person.id   = 10000;

            person.phone = new System.Collections.Generic.List <Person.PhoneNumber> ();
            Person.PhoneNumber num1 = new Person.PhoneNumber();
            num1.number = "123456789";
            num1.type   = 1;
            person.phone.Add(num1);

            Person.PhoneNumber num2 = new Person.PhoneNumber();
            num2.number = "87654321";
            num2.type   = 2;
            person.phone.Add(num2);

            address.person.Add(person);

            Person person1 = new Person();

            person1.name  = "Bob";
            person1.id    = 20000;
            person1.phone = new System.Collections.Generic.List <Person.PhoneNumber> ();
            Person.PhoneNumber num3 = new Person.PhoneNumber();
            num3.number = "01234567890";
            num3.type   = 3;
            person1.phone.Add(num3);

            address.person.Add(person1);

            byte[] data = address.encode();

            //Sproto.SprotoPack spack = new Sproto.SprotoPack ();

//			byte[] pack_data = spack.pack (data);

            //Sproto.SprotoStream stream = new SprotoStream ();
            double b = this.cur_mseconds();

            for (int i = 0; i < 1000000; i++)
            {
                address.init(data);
//				int len = address.encode (stream);
//				stream.Seek (0, System.IO.SeekOrigin.Begin);
//				spack.pack (stream.Buffer, len);

//				byte[] unpack_data = spack.unpack (pack_data);
//				address.init (unpack_data);
            }
            double e = this.cur_mseconds();

            Console.WriteLine("total: " + (e - b) / 1000 + "s");
        }
コード例 #3
0
ファイル: Test.cs プロジェクト: HeYuHan/ppt_demo
    public override void OnMessage()
    {
        tutorial.AddressBook ab = ReadProtoBuf <tutorial.AddressBook>();
        UnityEngine.Debug.Log("on message......");

        AddressBook abook = new AddressBook();

        Person p = new Person();

        p.email = "asdfasdfsdaf";
        p.id    = 1;
        p.name  = "xxxxxx";

        Person.PhoneNumber n = new Person.PhoneNumber();
        n.number = "fffffff";
        n.type   = Person.PhoneType.HOME;
        p.phone.Add(n);

        abook.person.Add(p);
        BeginWrite();
        WriteProtoBuf <AddressBook>(abook);
        EndWrite();
    }
コード例 #4
0
        public static void Run()
        {
            Console.WriteLine("Starting speed test...");

            AddressBook    ab  = new AddressBook();
            NetAddressBook nab = new NetAddressBook();

            ab.List  = new List <Person>();
            nab.List = new List <NetPerson>();
            //Generating structures
            for (int n = 0; n < 5000; n++)
            {
                Person p = new Person();
                p.Name  = "Alice" + n;
                p.Id    = 17532;
                p.Email = "*****@*****.**";
                p.Phone = new List <Person.PhoneNumber>();
                ab.List.Add(p);

                NetPerson np = new NetPerson();
                np.Name  = p.Name;
                np.Id    = p.Id;
                np.Email = p.Email;
                np.Phone = new List <NetPerson.NetPhoneNumber>();
                nab.List.Add(np);

                for (int m = 0; m < 1000; m++)
                {
                    Person.PhoneNumber pn = new Person.PhoneNumber();
                    pn.Type   = Person.PhoneType.MOBILE;
                    pn.Number = m.ToString();
                    p.Phone.Add(pn);

                    NetPerson.NetPhoneNumber npn = new NetPerson.NetPhoneNumber();
                    npn.Type   = Person.PhoneType.MOBILE;
                    npn.Number = pn.Number;
                    np.Phone.Add(npn);
                }
            }

            using (MemoryStream ms = new MemoryStream())
            {
                //Serialize
                DateTime start = DateTime.Now;
                AddressBook.Serialize(ms, ab);
                TimeSpan serialize = DateTime.Now - start;
                Console.WriteLine("Speed test: Serialize " + ab.List.Count + " posts in   " + serialize.TotalSeconds + " s");

                //Deserialize
                ms.Seek(0, SeekOrigin.Begin);
                start = DateTime.Now;
                var      dab         = AddressBook.Deserialize(new StreamRead(ms));
                TimeSpan deserialize = DateTime.Now - start;
                Console.WriteLine("Speed test: Deserialize " + dab.List.Count + " posts in " + deserialize.TotalSeconds + " s");
            }

            using (MemoryStream ms = new MemoryStream())
            {
                //Serialize
                DateTime start = DateTime.Now;
                ProtoBuf.Serializer.Serialize(ms, nab);
                TimeSpan serialize = DateTime.Now - start;
                Console.WriteLine("Protobuf-net: Serialize " + nab.List.Count + " posts in   " + serialize.TotalSeconds + " s");

                //Deserialize
                ms.Seek(0, SeekOrigin.Begin);
                start = DateTime.Now;
                var      dab         = ProtoBuf.Serializer.Deserialize <NetAddressBook>(ms);
                TimeSpan deserialize = DateTime.Now - start;
                Console.WriteLine("Protobuf-net: Deserialize " + dab.List.Count + " posts in " + deserialize.TotalSeconds + " s");
            }
        }