闲话少说,直接上代码:
String test = "{\"name\":\"Peter\"}"; long t1 = System.currentTimeMillis(); JSONObject jsonObject = JSONObject.fromObject(test); long t2 = System.currentTimeMillis(); System.out.println("net.sf.json.JSONObject 转换耗时:" + (t2-t1)); long t3 = System.currentTimeMillis(); com.alibaba.fastjson.JSONObject fastJson = com.alibaba.fastjson.JSONObject.parseObject(test); long t4 = System.currentTimeMillis(); System.out.println("com.alibaba.fastjson.JSONObject 转换耗时:" + (t4-t3)); System.out.println("时间相差倍数:" + (t2-t1)/(t4-t3));
主要的目的是想测试一下json转换的速度。下面是打印的结果:
net.sf.json.JSONObject 转换耗时:2884 com.alibaba.fastjson.JSONObject 转换耗时:52 时间相差倍数:55
原文地址:http://blog.csdn.net/hupitao/article/details/45395497