MessagePack test

Date: 2019-11-25
const Promise = require("bluebird");
const fsNode = require("fs");
const fs = Promise.promisifyAll(fsNode);
const msgpack = require("msgpack-lite");

process.on('unhandledRejection', (reason, promise) => {
	console.log('Unhandled Rejection at:', promise, 'reason:', reason);
});

process.on('uncaughtException', (err, origin) => {
	console.log(
		process.stderr.fd,
		`Caught exception: ${err}\n` +
		`Exception origin: ${origin}`
	);
});

function run() {
	return fs.readFileAsync("data.json")
		.then(data => {
			console.time("json-decode")
			const obj = JSON.parse(data);
			console.timeEnd("json-decode")

			console.time("json-encode")
			const str = JSON.stringify(obj);
			console.timeEnd("json-encode")
			console.log(str.length);

			console.time("encode");
			const str2 = msgpack.encode(obj)
			console.timeEnd("encode")
			console.log(str2.length);

			console.time("decode");
			const msgpk = msgpack.decode(str2);
			console.timeEnd("decode");
		});
};

run();

/*
json-decode: 60.222ms
json-encode: 43.728ms
9172547
encode: 166.285ms
7818978
decode: 313.279ms
*/

29370cookie-checkMessagePack test