msgpack对json的压缩优化测试

1)npm上msgpack模块

https://www.npmjs.com/package/msgpack-lite

2)app.js

var msgpack = require("msgpack-lite");

var obj = {
    name:"jianan", 
    age:28,
};

var json_str = JSON.stringify(obj);
console.log("json编码后长度=", json_str.length); 

var bin = msgpack.encode(obj);
console.log("msgpack编码后长度=", bin.length); 
console.log("msgpack编码后二进制为=", bin); 

var decode_bin = msgpack.decode(bin);
console.log("解码后数据=", decode_bin);

/**
json编码后长度= 26
msgpack编码后长度= 18
msgpack编码后二进制为= 
解码后数据= { name: 'jianan', age: 28 }
 */

经过几个对比,发现msgpack压缩后大小约为json的70%

你可能感兴趣的:(msgpack对json的压缩优化测试)