public static void Test() { var userinfo = new SerializeTestUserInfo(); userinfo.EmailState = 1; userinfo.FaceBookName = Guid.NewGuid().ToString("N"); userinfo.FaceBookState = 1; userinfo.Follow = 100; userinfo.GoogleName = Guid.NewGuid().ToString("N"); userinfo.GoogleState = 2; userinfo.PhoneState = 3; userinfo.Subscribe = 10; userinfo.ToFollow = 1000; userinfo.TwitterName = Guid.NewGuid().ToString("N"); userinfo.TwitterState = 132; userinfo.UserAvatarUrl = "http://www.example.com/useravatar"; userinfo.UserId = 1; int size = 10000; var stopwatch = new Stopwatch(); stopwatch.Start(); for (int i = 0; i < size; i++) { var u = userinfo.Clone(); Adf.JsonHelper.Serialize(u); } stopwatch.Stop(); Console.WriteLine("json:" + stopwatch.ElapsedMilliseconds); stopwatch.Reset(); stopwatch.Start(); for (int i = 0; i < size; i++) { var u = userinfo.Clone(); using (var m = new MemoryStream()) { ProtoBuf.Serializer.NonGeneric.Serialize(m, u); } } stopwatch.Stop(); Console.WriteLine("protobuf:" + stopwatch.ElapsedMilliseconds); Console.ReadLine(); }
private static SerializeTestUserInfo createUserInfo() { var userinfo = new SerializeTestUserInfo(); userinfo.EmailState = 1; userinfo.FaceBookName = Guid.NewGuid().ToString("N"); userinfo.FaceBookState = 1; userinfo.Follow = 100; userinfo.GoogleName = Guid.NewGuid().ToString("N"); userinfo.GoogleState = 2; userinfo.PhoneState = 3; userinfo.Subscribe = 10; userinfo.ToFollow = 1000; userinfo.TwitterName = Guid.NewGuid().ToString("N"); userinfo.TwitterState = 132; userinfo.UserAvatarUrl = "http://www.example.com/useravatar"; userinfo.UserId = 1; return(userinfo); }
/// <summary> /// clone a new object /// </summary> public object Clone() { var obj = new SerializeTestUserInfo(); obj.UserId = this.UserId; obj.Follow = this.Follow; obj.ToFollow = this.ToFollow; obj.Subscribe = this.Subscribe; obj.PhoneState = this.PhoneState; obj.EmailState = this.EmailState; obj.FaceBookState = this.FaceBookState; obj.TwitterState = this.TwitterState; obj.GoogleState = this.GoogleState; obj.FaceBookName = this.FaceBookName; obj.TwitterName = this.TwitterName; obj.GoogleName = this.GoogleName; obj.UserAvatarUrl = this.UserAvatarUrl; return(obj); }