HTML Preparation code:
x
 
1
2
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script>
Script Preparation code:
 
var max = 100000;
var arr = [];
for (var i = 0; i <= max; i++) { arr.push(i); }
Tests:
  • Lodash

     
    arr.forEach(() => {
      let object = { 'a': { 'b': 2 } };
      let other = { 'a': { 'b': 1, 'c': 3 } };
      _.defaultsDeep(object, other);
    })
  • Native

     
    function defaultsDeep(target, ...sources) {
      sources.forEach(source => {
        Object.keys(source).forEach(key => {
          if (typeof source[key] === 'object') {
            if (!target[key]) {
              Object.assign(target, { [key]: {} });
            }
            defaultsDeep(target[key], source[key]);
          } else {
            if (!target[key]) {
              Object.assign(target, { [key]: source[key] });
            }
          }
        });
      });
      return target;
    }
    arr.forEach(() => {
      let object = { 'a': { 'b': 2 } };
      let other = { 'a': { 'b': 1, 'c': 3 } };
      defaultsDeep(object, other);
    });
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    Lodash
    Native

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 7 months ago)
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36
Chrome 128 on Mac OS X 10.15.7
View result in a separate tab
Test name Executions per second
Lodash 34.5 Ops/sec
Native 39.4 Ops/sec