Run details:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36
Chrome 130
Mac OS X 10.15.7
Desktop
4 months ago
Test name Executions per second
deepclone 167270352.0 Ops/sec
JSON Parse 120818824.0 Ops/sec
Object.assign 166235760.0 Ops/sec
Tests:
  • deepclone

    x
     
    function deepClone(obj) {
        if (obj === null || typeof obj !== 'object') {
            return obj;
        }
        const clone = Array.isArray(obj) ? [] : {};
        for (let key in obj) {
            if (obj.hasOwnProperty(key)) {
                clone[key] = deepClone(obj[key]);
            }
        }
        return clone;
    }
    var n = {foo: 'bar', hello: [{hello: 'world', foo: 'bar'},{hello: 'world', foo: 'bar'},{hello: 'world', foo: 'bar'},{hello: 'world', foo: 'bar'}]};
    while (n.length < 1000) {
        n = deepClone(n);
    }
  • JSON Parse

     
    var n = {foo: 'bar', hello: [{hello: 'world', foo: 'bar'},{hello: 'world', foo: 'bar'},{hello: 'world', foo: 'bar'},{hello: 'world', foo: 'bar'}]};
    while(n.length < 1000) {
        n = JSON.parse(JSON.stringify(n))
    }
  • Object.assign

     
    var n = {foo: 'bar', hello: [{hello: 'world', foo: 'bar'},{hello: 'world', foo: 'bar'},{hello: 'world', foo: 'bar'},{hello: 'world', foo: 'bar'}]};
    while(n.length < 1000) {
        n = Object.assign({}, n);
    }