每一年都奔走在自己热爱里

没有人是一座孤岛,总有谁爱着你

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的漏洞比较多,大家使用的时候注意。

posted @   星星之草%  阅读(284)  评论(2编辑  收藏  举报
相关博文:
阅读排行:
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库
点击右上角即可分享
微信分享提示