mcollina/msgpack5

Add benchmark results compared to JSON to README?

brandonros opened this issue · 3 comments

encodedecode_json.js

var msg = { hello: 'world' }
var encode = JSON.stringify
var decode = JSON.parse
var max = 100000
var start
var stop
var i

function run () {
  for (i = 0; i < max; i++) {
    decode(encode(msg))
  }
}

// preheat
run()

start = Date.now()
run()
stop = Date.now()
console.log('time', stop - start)
console.log('decode/s', max / (stop - start) * 1000)
$ node encodedecode_json.js
time 79
decode/s 1265822.7848101268

compared to

$ node encodedecode.js 
time 1594
decode/s 62735.25721455458

Am I misunderstanding something?...

Me too

JSON methods are native functions heavily micro-optimized by browser vendors/nodejs C++ devs. It's very difficult to come up with something faster written purely in js, but relatively easy --- with something better: extensible, compact and supporting more types out of box.

Really hope there is some maintained benchmark (esp. comparing to JSON) for this project. It is very hard to decide without knowing the circumstances that MessagePack is actually better than JSON.