Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
native for in loop vs lodash omit
(version: 0)
Comparing performance of:
lodash omit vs native for in loop
Created:
6 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.4/lodash.min.js"></script>
Script Preparation code:
var allHeaders = { 'Accept-Encoding': 'gzip,deflate', 'Accept-Language': 'en-US', 'Content-Type': 'application/json', 'User-Agent': `(compatible; Mozilla/5.0; MSIE 9.0; Trident/5.0;})`, 'Proxy-Connection': 'Keep-Alive', Connection: 'Keep-Alive', Accept: 'application/hal+json, application/json', }; function omit(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
Tests:
lodash omit
_.omit(allHeaders, 'Accept-Encoding');
native for in loop
omit(allHeaders, ['Accept-Encoding']);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
lodash omit
native for in loop
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36 Edg/129.0.0.0
Browser/OS:
Chrome 129 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
lodash omit
916127.5 Ops/sec
native for in loop
936351.9 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 considered. **Benchmark Definition** The benchmark is designed to compare two approaches for removing specific properties from an object: 1. **Native `for` loop**: This approach uses a traditional `for` loop to iterate through the object's properties and exclude the specified ones. 2. **Lodash `omit` function**: This approach uses the `omit` function from the Lodash library, which is a utility library for functional programming in JavaScript. **Options Compared** The benchmark compares two options: 1. **Lodash `omit` function** 2. **Native `for` loop** **Pros and Cons of Each Approach** * **Lodash `omit` function**: + Pros: - Concise and readable code - Less prone to errors due to its functional programming nature + Cons: - Requires an additional library (Lodash) to be included in the test environment - May have a slightly higher overhead due to the inclusion of this library * **Native `for` loop**: + Pros: - No additional libraries are required - Can be optimized for performance by using a caching mechanism or other techniques + Cons: - More verbose and error-prone code - May require more careful tuning to optimize its performance **Library: Lodash** The `omit` function from the Lodash library is used to remove specific properties from an object. The library provides a range of utility functions for functional programming, including `omit`, which simplifies the process of removing properties from an object. **Special JS Feature/Syntax** There doesn't appear to be any special JavaScript features or syntax being tested in this benchmark. Both approaches use standard JavaScript syntax and do not rely on any advanced features like async/await, destructuring, or es6+ syntax. **Other Alternatives** If the `omit` function from Lodash is not an option, other alternatives for removing properties from an object include: * Using a library like jQuery's `$.omit` function * Implementing a custom solution using only vanilla JavaScript * Using a different utility library that provides similar functionality It's worth noting that for simple cases, the native `for` loop approach may be sufficient and more efficient. However, for more complex cases or when working with larger datasets, the Lodash `omit` function can provide a convenient and readable solution.
Related benchmarks:
Lodash forOwn vs Native keys + forEach
Lodash forOwn vs Native keys + forEach 2
big lodash vs nativejs foreach
Lodash Object Iteration vs Native
object key iteration - lodash vs native custom implementation
Comments
Confirm delete:
Do you really want to delete benchmark?