Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash omit vs Native delete - My
(version: 0)
Comparing performance of:
Native delete vs assign vs Lodash omit
Created:
2 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:
data = { a: 1, b: 2, c: 3, d: 4 }
Tests:
Native delete
const meta = Object.assign({}, data); delete meta.a; delete meta.b; return meta;
assign
return (({ a, b, ...o }) => o)(data)
Lodash omit
return _.omit(data, ['a', 'b']);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Native delete
assign
Lodash omit
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 years ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36
Browser/OS:
Chrome 122 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Native delete
4218994.5 Ops/sec
assign
9371661.0 Ops/sec
Lodash omit
1969801.5 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark and explain what's being tested, compared, and other considerations. **Benchmark Overview** The benchmark is designed to compare three different approaches for removing properties from an object: native `delete`, Lodash's `omit` function, and `assign`-based approach. The test cases are meant to measure which approach is faster. **Test Cases** 1. **Native Delete**: This approach uses the native `delete` operator to remove properties from the `data` object. It creates a new object using `Object.assign()` and then deletes specific properties from it. 2. **Lodash Omit**: This approach uses Lodash's `omit` function, which removes properties from an object based on an array of keys. In this case, it passes the `data` object as an argument and specifies an array of keys to omit (`['a', 'b']`). 3. **Assign-Based Approach**: This approach creates a new object using the spread operator (`{...}`) and assigns properties from the original `data` object while omitting specific ones. **Comparison** The benchmark compares the performance of each approach, measured in executions per second (ExecutionsPerSecond). The goal is to determine which approach is faster. **Pros and Cons** 1. **Native Delete**: This approach has: * Pros: Simple, efficient, and doesn't require any external libraries. * Cons: May not be as flexible or convenient than other approaches. 2. **Lodash Omit**: This approach has: * Pros: Convenient, flexible, and easy to use, especially for removing multiple properties at once. * Cons: Requires an additional library (Lodash) and may have performance overhead. 3. **Assign-Based Approach**: This approach has: * Pros: Flexible and easy to customize, as it uses the spread operator and can add or remove properties dynamically. * Cons: May be less efficient than native `delete` and Lodash's `omit`, especially for large objects. **Library Considerations** Lodash is a popular utility library that provides various functions for working with JavaScript objects. In this case, its `omit` function is used to remove properties from an object based on an array of keys. **Special JS Feature/Syntax** This benchmark doesn't use any special JavaScript features or syntax beyond the standard language. However, if you were to modify the `assign-Based Approach`, you could explore using other advanced techniques like `Object.assign()` with the `with` statement or using a library like `merge-deep` for more complex object merging. **Alternatives** If you're looking for alternatives to Lodash's `omit` function, you might consider: 1. **Utility libraries**: Other utility libraries like `lodash-es`, `ramda`, or `preact-immutable` offer similar functionality. 2. **Native implementations**: You could write a native implementation of the `omit` function using JavaScript's built-in `Object.keys()` and `reduce()` methods. 3. **Custom solutions**: Depending on your specific use case, you might find it more efficient to create a custom solution using a different approach. Keep in mind that each alternative will have its pros and cons, and the best choice ultimately depends on your project's requirements, performance needs, and personal preference.
Related benchmarks:
Lodash omit vs Native delete
Lodash omit VS delete
Lodash omit vs Native object destruction
Lodash omit vs Native delete - Mav
lodash unset vs lodash omit vs native delete
Comments
Confirm delete:
Do you really want to delete benchmark?