Run details:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36
Chrome 87
Mac OS X 10.15.6
Desktop
4 years ago
Test name Executions per second
simpleStringify 1092253.6 Ops/sec
JSON.stringify 2171273.5 Ops/sec
Script Preparation code:
AخA
 
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"}
Tests:
  • simpleStringify

     
    simpleStringify(testData);
  • JSON.stringify

     
    JSON.stringify(testData)