⽤JDK和JasonJson⼯具进⾏序列化性能的对⽐ int c_times=1000000;
long lvTm=System.currentTimeMillis();
byte[] lvBytes=null;
for (int i=1;i<=c_times;i++) {
lvBytes=JRedisUtils.serialize(lvRet);
}
System.out.println("Byte array length:"+lvBytes.length);
System.out.println("Serialize by ObjectOutputStream.writeObject, use:"+(System.currentTimeMillis()-lvTm));
TableResponseBean lvNewPage=null;
lvTm=System.currentTimeMillis();
分形for (int i=1;i<=c_times;i++) {
lvNewPage=JRedisUtils.unSerialize(lvBytes);
蓝与白}
System.out.println("UNSerialize adObject, use:"+ (System.currentTimeMillis()-lvTm));
String lvTmp=null;
lvTm=System.currentTimeMillis();
for (int i=1;i<=c_times;i++) {
lvTmp=JsonUtils.jsonFromObject(lvRet);
}
System.out.println("Serialize by JasonTool, Use:"+(System.currentTimeMillis()-lvTm));
System.out.println("Json String length:"+lvTmp.length());
lvTm=System.currentTimeMillis();
for (int i=1;i<=c_times;i++) {
lvNewPage= adValue(lvTmp, new TypeReference<TableResponseBean>() {
});
}
System.out.println("UNSerialize by JasonTool, Use:"+(System.currentTimeMillis()-lvTm));
System.out.println(lvNewPage);
看控制台输出:
==> Preparing: select fa_login, fa_name, fa_status, fa_type, fa_create_by, fa_create_dt, fa_update_by, fa_update_dt, fa_email, fa_passwd, fa_remark, fa
==> Parameters: A(String), admin(String), hufei(String)
<== Columns: fa_login, fa_name, fa_status, fa_type, fa_create_by, fa_create_dt, fa_update_by, fa_update_dt, fa_email, fa_passwd, fa_remark, fa_staff_id, fa_ <== Row: admin, 管理员, A, A, test1, 2016-09-19 15:24:40.594, supuser1, 2016-10-14 15:47:35.312, , d1841df9a9ead353f339dd239a1b4676, , , 9711
<== Row: hufei, 胡飞, A, N, 00001, 2017-03-21 09:39:43.903, 00001, 2017-03-22 12:06:36.768, , ab257d341f5d5afe96bc489a2534b7d8, , , null
<== Total: 2
==> Preparing: select count(*) as cc from ta_user WHERE fa_status = ? and fa_login = any(array[ ? , ? ])
==> Parameters: A(String), admin(String), hufei(String)
<== Columns: cc
<== Row: 2
<== Total: 1
Status: A<br/>
Login ID: admin,hufei<br/>
Byte array length:1263
Serialize by ObjectOutputStream.writeObject, use:8478
UNSerialize adObject, use:32191
Serialize by JasonTool, Use:2261
住宅室内装饰装修管理办法Json String length:688
UNSerialize by JasonTool, Use:3338
地震逃生记{"errCode":0,"errMsg":"","errRef":"","result":{"pageSize":10,"rows":[{"fa_name":"管理员","fa_update_dt":1476431255312,"fa_status":"A","fa_update_by":"supuser1"
麦克斯韦理论对TableResponseBean对象 重复测试100W次读写: ⽤对象流写⼊对象, 对象的长度为1263个byte, ⽽⽤Jason ⼯具转为Json格式的字串长度为688.
⽤对象流读写的耗时为, 序列化为byte[]100W次花费 8478毫秒, 还原对象100W次花费时间为32191毫秒 ⽤Jason⼯具序列化为json string 100W次花费为 2261毫秒, 还原对象100W次花费时间为3338毫秒
吴宇平⽐jdk提供的序列化/还原缩短近乎4倍/10倍的时间,可见Jason提供的fast系列, 果然是fast.