Test name | Executions per second |
---|---|
simpleStringify | 913123.2 Ops/sec |
JSON.stringify | 1956672.1 Ops/sec |
function simpleStringify(o) {
let cache = [];
let data = JSON.stringify(o, function(key, value) {
if (typeof value === "object" && value !== null) {
if (cache.indexOf(value) !== -1) {
// Circular reference found, discard key
return;
}
// Store value in our collection
cache.push(value);
}
return value;
});
cache = null;
return data;
}
var testData = {"bar":"foo"}
simpleStringify(testData);
JSON.stringify(testData)