JSON vs replacer (v3)

Revision 3 of this benchmark created on


Preparation HTML

<script crossorigin src="https://unpkg.com/@msgpack/msgpack"></script>

Setup

function replacer(key, value) {
  if (this[key] instanceof Date) return { $date: this[key].toISOString() };
  return value;
}


const reviver = (key, value) =>
  (value instanceof Object && !!value.$date && new Date(value.$date)) || value;

data = Array(100).fill(0).map(() => new Date(Math.round(Math.random()*1000000000000)));

Test runner

Ready to run.

Testing in
TestOps/sec
Pure
JSON.parse(JSON.stringify(data));
ready
With reviver
const json = JSON.stringify(data, replacer);
const result = JSON.parse(json, reviver);
ready
Msgpack
const { decode, encode } = MessagePack;
decode(encode(data));
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.