fastJson和jackson性能对比
public static void main(String [] str) {
Map map = new HashMap<String,Object>();
map = getMapData(map,1000000);
JSONObject fastJson = new JSONObject();
long fastJsonBegin = System.currentTimeMillis();
//fastJson
System.out.println("fastJson-------------------------------------------------");
// System.out.println("fastJson"+fastJson.toJSONString(map));
fastJson.toJSONString(map);
long fastJsonEnd = System.currentTimeMillis();
System.out.println("fastJson-------------time------------------------------------"+(fastJsonEnd-fastJsonBegin));
//jackson
ObjectMapper jackson = new ObjectMapper();
long jacksonBegin = System.currentTimeMillis();
try {
System.out.println("jackson-------------------------------------------------");
//System.out.println("jackson"+jackson.writeValueAsString(map));
jackson.writeValueAsString(map);
long jacksonEnd = System.currentTimeMillis();
System.out.println("jackson-------------time------------------------------------"+(jacksonEnd-jacksonBegin));
} catch (JsonProcessingException e) {
e.printStackTrace();
}
}
public static Map getMapData(Map map,int count) {
for (int i = 0;i < count;i++) {
map.put("a"+i,i);
}
return map;
}
运行结果:
通过测试发现fastjson运行速度更胜一筹。
但最近几年fastjson的漏洞比较多,大家使用的时候注意。
本文来自博客园,作者:星星之草%,转载请注明原文链接:https://www.cnblogs.com/zhaodefu/p/16369941.html
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库