Skip to content

Instantly share code, notes, and snippets.

@lvzixun
Created January 29, 2015 07:41
Show Gist options
  • Save lvzixun/9e6be325aa4249564a95 to your computer and use it in GitHub Desktop.
Save lvzixun/9e6be325aa4249564a95 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
namespace TestProtoBufNet
{
class BenchMark
{
public BenchMark()
{
Member.AddressBook address = new Member.AddressBook();
Member.Person persion1 = new Member.Person();
persion1.name = "Alice";
persion1.id = 10000;
address.person.Add(persion1);
Member.Person.PhoneNumber num1 = new Member.Person.PhoneNumber();
num1.number = "123456789";
num1.type = 1;
persion1.phone.Add(num1);
Member.Person.PhoneNumber num2 = new Member.Person.PhoneNumber();
num2.number = "87654321";
num2.type = 2;
persion1.phone.Add(num2);
Member.Person persion2 = new Member.Person();
persion2.name = "Bob";
persion2.id = 20000;
address.person.Add(persion2);
Member.Person.PhoneNumber num3 = new Member.Person.PhoneNumber();
num3.number = "0123456789";
num3.type = 3;
persion2.phone.Add(num3);
double b = this.getCurMilliSeconds();
MemoryStream stream = new MemoryStream();
ProtoBuf.Serializer.Serialize(stream, address);
for (int i = 0; i < 1000000; i++)
{
stream.Seek(0, SeekOrigin.Begin);
ProtoBuf.Serializer.Serialize(stream, address);
//Member.AddressBook obj = ProtoBuf.Serializer.Deserialize<Member.AddressBook>(stream);
}
double e = this.getCurMilliSeconds();
Console.WriteLine("total: " + (e - b) / 1000 + "s");
}
private double getCurMilliSeconds()
{
TimeSpan ts = DateTime.Now - new DateTime(1960, 1, 1);
return ts.TotalMilliseconds;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment