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