您的位置:首页 > Web前端 > JavaScript

Newtonsoft 和 FastJson 的序列化和反序列化性能的对比

2013-08-15 00:23 639 查看
Newtonsoft 和 FastJson 是两个.NET下常用的JSON库。我在开发网络服务的时候使用JSON序列化,之前使用了Newtonsoft,后面听说FastJson性能更好,于是便对两个开源库的性能进行了对比测试。测试在本人笔记本上进行,参数:

  CPU:i5 3210M

  内存:8G

  操作系统:Win7 64位

  测试的对象类型:  

[Serializable]
public class MsgServerTrainInfo
{
public string TrainName { get; set; }
public string TargetType { get; set; }
public string GunType { get; set; }
public int GroupCount { get; set; }
public int BulletPerGroup { get; set; }
public string TimeMode { get; set; }
public int Seconds { get; set; }
public int CurrentGroup { get; set; }
public int LeftBullet { get; set; }
public int PassedMilliSecond { get; set; }
public string GameState { get; set; }
}


序列化测试结果:

5000次10000次50000次100000次
Newtonsoft63(ms)111(ms)476(ms)908(ms)
FastJson28(ms)59(ms)281(ms)564(ms)
反序列化测试结果

5000次10000次50000次100000次
Newtonsoft101(ms)213(ms)983(ms)1922(ms)
FastJson39 (ms)78(ms)387(ms)797(ms)
可见,FastJson在序列化和反序列化的性能相比Newtonsoft还是有比较大的优势的。其中,反序列化的性能优势更大一些。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: