Lodash omit vs Native delete - Ankur

3 years ago
User agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.2 Safari/605.1.15
Test name Executions per second
Native delete 853724.6 Ops/sec
Lodash omit 554169.2 Ops/sec
HTML Preparation code:
AخA
 
1
<script src="//cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js"></script>
Script Preparation code:
x
 
data = {
    abf: 'asd',
    message: 'koko',
   _id: '{{objectId()}}',
    index: '{{index()}}',
    guid: '{{guid()}}',
    isActive: '{{bool()}}',
    balance: '{{floating(1000, 4000, 2, "$0,0.00")}}',
    picture: 'http://placehold.it/32x32',
    age: '{{integer(20, 40)}}',
    eyeColor: '{{random("blue", "brown", "green")}}',
    name: '{{firstName()}} {{surname()}}',
    gender: '{{gender()}}',
    company: '{{company().toUpperCase()}}',
    email: '{{email()}}',
    phone: '+1 {{phone()}}',
    address: '{{integer(100, 999)}} {{street()}}, {{city()}}, {{state()}}, {{integer(100, 10000)}}',
    about: '{{lorem(1, "paragraphs")}}',
    registered: '{{date(new Date(2014, 0, 1), new Date(), "YYYY-MM-ddThh:mm:ss Z")}}',
    latitude: '{{floating(-90.000001, 90)}}',
    longitude: '{{floating(-180.000001, 180)}}'
}
keysToOmit = ['longitude', 'gender', 'guid', 'abf']
Tests:
  • Native delete

     
     Object.keys(data).forEach((key) => {
       keysToOmit.includes(key) && delete data[key];
    });
    return { 
      data
    }
  • Lodash omit

     
    return { 
      data: _.omit(data, keysToOmit)
    }
Open this result on MeasureThat.net