Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash omit vs Native delete - Ankur
(version: 0)
Comparing performance of:
Native delete vs Lodash omit
Created:
5 years ago
by:
Registered User
Jump to the latest result
HTML Preparation code:
<script src="//cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js"></script>
Script Preparation code:
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) }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Native delete
Lodash omit
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the world of JavaScript microbenchmarks. **What is being tested?** The provided benchmark tests two approaches to remove specific keys from an object: native `delete` and Lodash's `omit` function. **Options compared:** 1. **Native delete**: This approach uses the built-in `delete` operator to remove specified keys from the object. It iterates over the `keysToOmit` array and deletes each key that is present in the object. 2. **Lodash omit**: This approach uses Lodash's `omit` function, which takes an object and a list of keys to remove as arguments. It returns a new object with the specified keys removed. **Pros and Cons:** 1. **Native delete**: * Pros: + Lightweight and doesn't require any external libraries. + Fast, since it only involves a single operation (delete) on each key. * Cons: + Requires explicit iteration over the `keysToOmit` array, which can be slower than using an optimized library like Lodash. 2. **Lodash omit**: * Pros: + Faster and more efficient, since it leverages Lodash's optimized implementation. + Easier to read and maintain, as the code is concise and uses a familiar syntax (`.omit()`). * Cons: + Requires an external library (Lodash), which adds overhead in terms of size and complexity. **Library:** The `omit` function from Lodash is used in this benchmark. Lodash is a popular JavaScript utility library that provides a wide range of functions for tasks like array manipulation, object transformation, and more. **Special JS feature or syntax:** None mentioned explicitly in the provided code snippets. However, it's worth noting that some older browsers may not support modern ES6+ features used in this benchmark (e.g., template literals, `forEach` with a callback function). **Other alternatives:** For removing keys from an object without using Lodash, you could consider using: 1. **ES6 `delete` operator**: Similar to the native `delete` approach, but without the need for iteration. 2. **Array methods**: You can use array methods like `filter()` or `reduce()` to create a new object with the desired keys removed. Keep in mind that these alternatives may have different performance characteristics compared to using Lodash's optimized implementation. Here's an example of how you could rewrite the benchmark using ES6 `delete` operator: ```javascript keysToOmit.forEach((key) => { delete data[key]; }); return { data }; ``` And here's an example using array methods: ```javascript const result = {}; Object.keys(data).forEach((key) => { if (!keysToOmit.includes(key)) { result[key] = data[key]; } }); return result; ```
Related benchmarks:
_.includes vs includes() vs indexof
lodash vs es6 in filter method
aadasdsa
Lodash compact vs native
asdasdjkh askjdjkasdkjasd
Comments
Confirm delete:
Do you really want to delete benchmark?