Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash omit vs Native object destruction
(version: 0)
Comparing performance of:
Native object desctruction vs Lodash omit
Created:
5 years ago
by:
Guest
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 object = { 'a': 1, 'b': '2', 'c': 3 };
Tests:
Native object desctruction
var { a, c, ...result2 } = object; return result2
Lodash omit
return _.omit(object, ['a', 'c']);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Native object desctruction
Lodash omit
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
7 months ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.5 Safari/605.1.15
Browser/OS:
Safari 18 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Native object desctruction
40853924.0 Ops/sec
Lodash omit
7419271.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
**Benchmark Explanation** The provided benchmark measures the performance difference between two approaches to achieve object destruction in JavaScript: native object destruction and using the Lodash library's `omit` function. **Native Object Destruction** In this approach, an object is created with three properties (`a`, `b`, and `c`) and then destructured using a syntax similar to ES6 destructuring. The resulting object without the unwanted properties (`result2`) is returned from the function. This approach relies on JavaScript's native syntax for object destruction. **Pros of Native Object Destruction** 1. **Efficient**: Native object destruction is typically faster since it doesn't involve any additional library calls or overhead. 2. **Low Overhead**: The code required to implement this approach is minimal, with only a few lines needed to create the object and destructure it. **Cons of Native Object Destruction** 1. **Limited Browser Support**: Older browsers may not support ES6 features like destructuring, which could result in slower performance or errors. 2. **Less Intuitive for Non-Experienced Developers**: While familiar to those with experience in JavaScript, this approach might seem less intuitive for developers without prior knowledge of object destruction. **Lodash Omit** In contrast, the Lodash library's `omit` function is used to achieve object destruction. This approach involves calling a separate library function and passing an array of keys to exclude from the original object. **Pros of Lodash Omit** 1. **Wide Browser Support**: As a widely used library, Lodash is supported by most modern browsers. 2. **Easy to Use**: For developers familiar with the Lodash library, using `omit` can be straightforward and efficient. **Cons of Lodash Omit** 1. **Additional Library Overhead**: Calling an external function introduces additional overhead compared to native object destruction. 2. **Less Efficient**: Since it involves a separate library call, this approach might be slower than native object destruction. **Library Description - Lodash** Lodash is a popular JavaScript utility library that provides various functions for tasks such as array manipulation, object modification, and more. The `omit` function specifically returns a new object with the specified keys removed from the original object. **Other Considerations** 1. **ES6 Features**: This benchmark assumes familiarity with ES6 syntax like destructuring. If you're using older JavaScript versions or a different programming paradigm, this approach might not be feasible. 2. **Performance Variance Across Browsers**: As seen in the benchmark results, performance can vary significantly across browsers and devices. **Alternatives to Native Object Destruction** If native object destruction is not an option, other approaches could include: 1. Using `Object.assign()` with a new object that excludes unwanted properties. 2. Implementing a custom `delete` function for objects. 3. Utilizing libraries like Lodash or a similar utility library to perform object manipulation. Keep in mind that these alternatives may have their own trade-offs in terms of efficiency, browser support, and overall performance.
Related benchmarks:
lodash omit vs spread omit using babel
Lodash omit vs Native delete
lodash omit vs spread omit vs delete omit
lodash omit vs spread omit modified
Comments
Confirm delete:
Do you really want to delete benchmark?