4
回答
为啥hession 和 fastjson 差距这么大?
科大讯飞通用文字识别100000次/天免费使用。立即申请   

为啥hession 和 fastjson 差距这么大?是代码有问题?

{"a":"111","bd":"ccc","ccasd":"e323223","de":"dada"}
1081 ---fastjson
[B@da9e37
6564 --- hession


Process finished with exit code 0


package com.company; import com.alibaba.fastjson.JSON; import com.caucho.hessian.io.HessianOutput; import java.io.ByteArrayOutputStream; import java.io.Serializable; public class Main implements Serializable {
    String a = "111";
    String bd = "ccc";
    String ccasd = "e323223";
    String de = "dada"; public String getA() { return a;
    } public void setA(String a) { this.a = a;
    } public String getBd() { return bd;
    } public void setBd(String bd) { this.bd = bd;
    } public String getCcasd() { return ccasd;
    } public void setCcasd(String ccasd) { this.ccasd = ccasd;
    } public String getDe() { return de;
    } public void setDe(String de) { this.de = de;
    } public static void main(String[] args)throws Exception{
        Main main = new Main();
        String mainJson = null; long t1 = System.currentTimeMillis(); for (int i = 0; i < 10000 * 100; ++i) {
            mainJson = JSON.toJSONString(main);
        }
        System.out.println(mainJson);
        System.out.println(System.currentTimeMillis() - t1); long t2 = System.currentTimeMillis(); byte[] mainByte = null; for (int i = 0; i < 10000 * 100; ++i) {

            ByteArrayOutputStream os = new ByteArrayOutputStream(1024);
            HessianOutput ho = new HessianOutput(os);
            ho.writeObject(main);
            mainByte = os.toByteArray();

        }
        System.out.println(mainByte);
        System.out.println(System.currentTimeMillis() - t2);

    }
	

}



举报
精通吹水
发帖于2年前 4回/1K+阅
顶部