加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

Json工具类转化速度比较

发布时间:2020-12-13 20:08:34 所属栏目:PHP教程 来源:网络整理
导读:闲话少说,直接上代码: 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));

闲话少说,直接上代码:

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));


主要的目的是想测试1下json转换的速度。下面是打印的结果:


net.sf.json.JSONObject 转换耗时:2884 com.alibaba.fastjson.JSONObject 转换耗时:52 时间相差倍数:55

看到结果,供君选择。



(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读