Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash omit vs es omit vs compiled omit vs rest and delete omit
(version: 0)
Comparing performance of:
Lodash vs es omit vs compiled omit vs rest and delete omit
Created:
4 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script> <script src=''> </script>
Script Preparation code:
var omit1 = (originalObj = {}, keysToOmit = []) => Object.fromEntries( Object.entries(originalObj) .filter(([key]) => !keysToOmit.includes(key)) ) var omit2 = new Function('obj', 'if (!obj) return {}; const { a, d, i, ...res } = obj; return res;'); var omit3 = (originalObject = {}, keysToOmit = []) => { const clonedObject = { ...originalObject }; for (const path of keysToOmit) { delete clonedObject[path] } return clonedObject; }
Tests:
Lodash
const obj = { a:1, b:1, c:1, d:1, e:1, f:1, g:1, h:1, i:1, } const n = _.omit(obj, ['a','d','i']);
es omit
const obj = { a:1, b:1, c:1, d:1, e:1, f:1, g:1, h:1, i:1, } const n = omit1(obj, ['a','d','i']);
compiled omit
const obj = { a:1, b:1, c:1, d:1, e:1, f:1, g:1, h:1, i:1, } const n = omit2(obj, ['a','d','i']);
rest and delete omit
const obj = { a:1, b:1, c:1, d:1, e:1, f:1, g:1, h:1, i:1, } const n = omit3(obj, ['a','d','i']);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
Lodash
es omit
compiled omit
rest and delete omit
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
7 days ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:150.0) Gecko/20100101 Firefox/150.0
Browser/OS:
Firefox 150 on Mac OS X 10.15
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Lodash
1264347.2 Ops/sec
es omit
2620821.0 Ops/sec
compiled omit
9194213.0 Ops/sec
rest and delete omit
1816985.2 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Measuring the performance of different approaches to removing properties from an object is a common task in JavaScript development. **Overview** The provided benchmark measures the execution speed of four different approaches: 1. Lodash's `omit` function 2. A custom implementation using ES6 syntax (`es omit`) 3. A compiled version of the same custom implementation (likely using `Function` constructor or a similar technique to create a compiled, optimized version) 4. Another custom implementation that uses rest and delete operators (`rest and delete omit`) **Approach 1: Lodash's `omit` function** Lodash is a popular JavaScript library that provides various utility functions for tasks like array manipulation, string processing, and more. The `omit` function takes an object and an array of keys to omit as arguments and returns a new object with the specified keys removed. **Pros**: Well-tested and widely used, so there's likely extensive caching and optimization in place to improve performance. **Cons**: Requires an additional library dependency (Lodash), which might introduce overhead for users without it installed. **Approach 2: Custom implementation using ES6 syntax (`es omit`)** This implementation uses the spread operator (`...`) and `Object.fromEntries()` method to create a new object with only the desired properties. It's a concise and expressive way to implement object removal. **Pros**: Lightweight and easy to read, as it leverages modern JavaScript features. **Cons**: Might be slower than compiled versions due to the overhead of function calls and method lookups. **Approach 3: Compiled version (`compiled omit`)** The compiled version is likely created using a similar technique to `es omit`, but with additional optimizations applied during compilation. This can result in faster execution times, as the overhead of function calls and method lookups is minimized. **Pros**: Can offer significant performance improvements compared to custom implementations. **Cons**: Requires manual effort to compile the code, which can be error-prone. **Approach 4: Custom implementation using rest and delete operators (`rest and delete omit`)** This approach uses rest operator syntax (`...`) to create a new object with only the desired properties, and then iterates over an array of keys to delete. It's a simple and easy-to-understand way to implement object removal. **Pros**: Easy to read and understand, as it leverages modern JavaScript features. **Cons**: Might be slower than compiled versions due to the overhead of function calls and method lookups. In summary, the choice of approach depends on trade-offs between performance, readability, and maintainability. If speed is critical, a compiled version might offer the best results. However, if ease of use and understanding are more important, a custom implementation using ES6 syntax or rest and delete operators could be a better fit. **Alternatives** If you're not comfortable with using Lodash or custom implementations, there are alternative approaches you can consider: * Using `Object.assign()` with an empty object to create a new object without the specified properties. * Implementing your own object removal logic using `for...in` and `delete` operators. However, these alternatives might not offer the same level of performance as optimized custom implementations or compiled versions.
Related benchmarks:
Lodash omit vs es omit vs compiled omit vs rest and delete omit vs babel
Lodash omit vs es omit vs compiled omit vs rest and delete omit vs babel - a lot of different objects
Lodash omit vs es omit vs compiled omit vs rest and delete omit vs babel vs omit as dest and rest - a lot of different objects
Lodash omit vs es omit vs compiled omit vs rest and delete omit vs babel vs omit as dest and rest vs prod version - v1
Comments
Confirm delete:
Do you really want to delete benchmark?