首页 > 代码库 > ServiceStack.Text / Newtonsoft.Json 两种json序列化性能比较
ServiceStack.Text / Newtonsoft.Json 两种json序列化性能比较
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 / Newtonsoft.Json 两种json序列化性能比较
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。