Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash vs Native JS: omit
(version: 0)
Comparison of _.omit and JS native suggestion
Comparing performance of:
Lodash _.omit() vs Native JS solution
Created:
6 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.15/lodash.min.js"></script>
Script Preparation code:
var data = {}; for(var i=0; i<10; i++){ data[`key${i}`] = i; } var keysToOmit = []; for(i=0; i<9; i++){ keysToOmit.push(`key${i}`); }
Tests:
Lodash _.omit()
_.omit(data, keysToOmit)
Native JS solution
var {key0, key1, key2, key3, key4, key5, key6, key7, key8, ...result} = data;
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Lodash _.omit()
Native JS solution
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 break down the benchmark and explain what's being tested. **What is being tested?** The benchmark compares two approaches to remove specific keys from an object: 1. Using Lodash's `_.omit` function 2. A native JavaScript solution using destructuring assignment **Options compared:** * **Lodash _.omit**: This function takes an object and an array of keys to omit as arguments, returning a new object with the specified keys removed. * **Native JS solution (using destructuring)**: This approach uses destructuring assignment to extract specific values from the object, effectively removing the unwanted keys. **Pros and cons of each approach:** * **Lodash _.omit**: Pros: + Concise and readable code + Handles complex objects with nested properties * Cons: + Requires an additional library (Lodash) + May have performance overhead due to function call * **Native JS solution (using destructuring)**: Pros: + No additional library required + Often faster than function calls, as it's a direct operation on the object * Cons: + Can be less readable for complex objects or large datasets + May require more code and setup **Library used:** The benchmark uses Lodash version 4.17.15, which is a popular utility library for JavaScript. **Special JS feature/syntax:** This benchmark doesn't use any special JavaScript features or syntax. However, it does rely on the fact that modern browsers support ES6+ features like destructuring assignment. **Other alternatives:** If you don't want to use Lodash, there are other libraries available that provide similar functionality, such as `omit` in Ramda or `pick` in Moment.js. Alternatively, you can use a custom implementation of the _.omit function without an external library. In terms of native JavaScript solutions, you could consider using `Object.fromEntries` and `Array.from` to achieve a similar result: ```javascript var {key0, key1, key2, key3, key4, key5, key6, key7, key8, ...result} = Object.fromEntries( Array(9) .fill(null) .map((_, i) => [`key${i}`, null]) ); ``` This approach would be even more concise than the native JavaScript solution using destructuring, but might still have some performance overhead due to function calls.
Related benchmarks:
lodash.keys vs Object.keys
lodash.keys vs Object.keys
Array.prototype.some vs Lodash some
Array.prototype.every vs Lodash every
Array.prototype.slice vs Lodash drop
Comments
Confirm delete:
Do you really want to delete benchmark?