JSON序列化现在应用非常多,尤其在前后端分离的情况下,平常大多数C#下都使用Newtonsoft.Json来操作,量少的情况下,还可以忽略,但量大的情况下就要考虑使用ServiceStack.Text来操作,序列化性能差不多,反序列化性能要高一倍左右
int count = 10000; User user = new User() { Id = 1, Name = "tyh", AddTime = DateTime.Now, Age = 15, Status = true }; string temp = String.Empty; User user1 = new User(); string temp1 = "{\"Id\": \"2\",\"Name\": \"xxc\",\"AddTime\": \"2016-09-07 10:10:10\",\"Age\": \"15\",\"Status\": \"true\"}"; Stopwatch sw = new Stopwatch(); sw.Restart(); for (int i = 0; i < count; i++) { temp = ServiceStack.Text.JsonSerializer.SerializeToString(user); } sw.Stop(); Response.Write("ServiceStack-Ser:" + sw.ElapsedMilliseconds + "</br>"); sw.Restart(); for (int i = 0; i < count; i++) { user1 = ServiceStack.Text.JsonSerializer.DeserializeFromString<User>(temp1); } sw.Stop(); Response.Write("ServiceStack-Des:" + sw.ElapsedMilliseconds + "</br>"); sw.Restart(); for (int i = 0; i < count; i++) { temp = Newtonsoft.Json.JsonConvert.SerializeObject(user); } sw.Stop(); Response.Write("Newtonsoft-Ser:" + sw.ElapsedMilliseconds + "</br>"); sw.Restart(); for (int i = 0; i < count; i++) { user1 = Newtonsoft.Json.JsonConvert.DeserializeObject<User>(temp1); } sw.Stop(); Response.Write("Newtonsoft-Des:" + sw.ElapsedMilliseconds + "</br>"); Response.End();
以下是测试结果,我只截一个图,其他自行测试吧
现在ServiceStack.Text是收费的了还好是开源,看到了有文章写的可以接触配额限制,转载过来
原文地址:http://blog.csdn.net/hao_ds/article/details/73648130
ServiceStack 4.0 开始已经成为商业产品,不再完全免费,好在是开源的,主要限制免费配额功能在ServiceStack.Text类库下的LicenseUtils.cs文件中,仅需从GitHub上下载源码后添加一行代码重新编译即可解除限制,如下图: