lodash omitBy vs Array.reduce omit by 100k

5 months ago
User agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36
Test name Executions per second
Lodash 2139758.2 Ops/sec
Native 5089964.5 Ops/sec
Native with Entries 6023474.0 Ops/sec
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 max2 = 100000;
var data = {};
for (var i = 0; i <= max2; i++) { data['id'] = i; }
Tests:
  • Lodash

     
    _.omitBy(data, (item) => item.id === 5000)
  • Native

     
    Object.keys(data).reduce((result, key) => {
      if (key !== 5000) {
        result[key] = data[key];
      }
      return result;
    }, {})
  • Native with Entries

     
    Object.entries(data).reduce((result, entry) => {
      if (entry[1] !== 5000) {
        result[entry[0]] = entry[1];
      }
      return result;
    }, {})
Open this result on MeasureThat.net