Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Delete element in object
(version: 1)
Comparing performance of:
Native delete vs Lodash omit vs Native delete 2 vs Native delete 3 vs Native delete multi vs Lodash omit multi vs Native delete 2 multi vs Native delete 3 multi
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:
var data = { abf: 'asd', a: 'dog', b: 'cat', c: 'mouse', message: 'koko', d: 'cow', e: 'horse', }
Tests:
Native delete
const meta = Object.assign({}, data); delete meta.message;
Lodash omit
_.omit(data, 'message');
Native delete 2
delete data.message;
Native delete 3
const {message, ...newData} = data;
Native delete multi
const meta = Object.assign({}, data); delete meta.message; delete meta.e;
Lodash omit multi
_.omit(data, ['message', 'e']);
Native delete 2 multi
delete data.message; delete data.e;
Native delete 3 multi
const {message, e, ...newData} = data;
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (8)
Previous results
Fork
Test case name
Result
Native delete
Lodash omit
Native delete 2
Native delete 3
Native delete multi
Lodash omit multi
Native delete 2 multi
Native delete 3 multi
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 explanation of the provided benchmark. **Benchmark Overview** The benchmark measures the performance of deleting elements from an object in JavaScript using different approaches: native `delete`, Lodash `omit` function, and destructuring assignment (`{...obj, prop: undefined}`). **Options Compared** 1. **Native delete**: Directly deleting a property from an object using the syntax `delete obj.prop;`. This approach is simple but may have performance overhead due to the overhead of property lookup. 2. **Lodash omit**: Using the Lodash `omit` function to remove a property from an object, which returns a new object with the desired properties removed. This approach is more flexible and can be used with multiple properties. 3. **Destructuring assignment**: Assigning a new object with only the desired properties using the syntax `{...obj, prop: undefined};`. This approach is concise but may have performance overhead due to the creation of a new object. **Pros and Cons** * **Native delete**: + Pros: Simple, fast, and widely supported. + Cons: May have performance overhead due to property lookup. * **Lodash omit**: + Pros: Flexible, can be used with multiple properties, and provides a more explicit removal of properties. + Cons: Requires an external library (Lodash), may have slower performance compared to native delete. * **Destructuring assignment**: + Pros: Concise, expressive, and can be used with multiple properties. + Cons: May have performance overhead due to object creation, not as widely supported. **Library: Lodash** Lodash is a popular JavaScript library that provides a wide range of utility functions for tasks such as array manipulation, string manipulation, and more. In this benchmark, the `omit` function is used to remove properties from an object. Lodash is often used in conjunction with other libraries or frameworks, but it can also be used as a standalone solution. **Special JS Feature: Destructuring Assignment** The destructuring assignment syntax (`{...obj, prop: undefined};`) is a modern JavaScript feature introduced in ECMAScript 2015 (ES6). It allows for concise and expressive way to create new objects with only the desired properties. While it's not required to know this feature to understand the benchmark, understanding its basics can help in appreciating the code. **Other Alternatives** If you're looking for alternatives to Lodash or want to explore other options: * **Array.prototype.filter()**: You could use `filter()` on an array of object properties to remove desired ones. * **Object.keys() and Array.prototype.forEach()**: You can iterate over object keys and manually delete the desired property using `delete obj[key];`. * **Other libraries**: Depending on your specific requirements, you might want to explore other libraries like `lodash.debounce()` for debouncing or `lodash.throttle()` for throttling.
Related benchmarks:
Merge list of objects
circleTest
CircleSmallTest
Lodash values vs Object.values
object iteration pravin
Comments
Confirm delete:
Do you really want to delete benchmark?