Run details:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.142 Safari/537.36
Chrome 75
Windows
Desktop
5 years ago
Test name Executions per second
simpleStringify 608838.1 Ops/sec
JSON.stringify 1240313.4 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)