Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Loop over object: lodash vs Object.entries fork by d9k 3
(version: 0)
Comparing performance of:
lodash.each vs lodash.map vs Object.entries.map vs Object.entries + for vs Object.entries + for..of vs forEach vs for..in vs lodash.forOwn
Created:
6 years ago
by:
Registered User
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 Preparation code:
var obj = Array.from({ length: 10000 }).map((value, i) => i).reduce((val, v) => { val[v] = v; return val; }, {})
Tests:
lodash.each
_.each(obj, function(v, k) {})
lodash.map
_.map(obj, function(v, k) {})
Object.entries.map
Object.entries(obj).map(function([k, v]) {})
Object.entries + for
const entries = Object.entries(obj); for (let i = 0; i < entries.length; i++) { const [k, v] = entries[i]; }
Object.entries + for..of
for (let [k, v] of Object.entries(obj)) { // }
forEach
Object.keys(obj).forEach(function (k) { let v = obj[k]; // });
for..in
for (const k in obj) { if (obj.hasOwnProperty(k)) { let v = obj[k]; } }
lodash.forOwn
_.forOwn(obj, function(v, k) { // });
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (8)
Previous results
Fork
Test case name
Result
lodash.each
lodash.map
Object.entries.map
Object.entries + for
Object.entries + for..of
forEach
for..in
lodash.forOwn
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 its various components. **Benchmark Definition** The test is comparing four approaches to iterate over an object: 1. Using `lodash.each` 2. Using `lodash.map` 3. Using `Object.entries` with a for loop 4. Using `Object.entries` with a for...of loop **Options Compared** Each option has its own strengths and weaknesses. * **Lodash (`_.each` and `_map`)**: Lodash is a popular utility library that provides a lot of useful functions, including iteration methods. These functions are often faster than the built-in `for` loop but come with a larger footprint due to the library's dependencies. + Pros: Often faster, simpler code + Cons: Adds extra dependency, potential performance overhead * **Built-in `Object.entries` with for loop**: This approach uses the `Object.entries()` method to get an array of key-value pairs from the object and then loops through it using a traditional for loop. + Pros: Lightweight, no additional dependencies + Cons: Can be slower due to the overhead of the loop variable declaration * **Built-in `Object.entries` with for...of loop**: This approach is similar to the previous one but uses a for...of loop instead of a traditional for loop. The for...of loop is more modern and often faster. + Pros: Modern, potentially faster than traditional for loops + Cons: Still has the overhead of the loop variable declaration * **Built-in `forEach`**: This approach uses the built-in `forEach()` method to iterate over an array (or object in this case). + Pros: Simple, often faster than traditional for loops + Cons: Not designed specifically for iterating over objects, can be slower **Library Descriptions** The benchmark uses two libraries: 1. **Lodash**: A popular utility library that provides a lot of useful functions, including iteration methods (`_.each` and `_map`). Lodash is often faster than the built-in `for` loop but comes with a larger footprint due to its dependencies. 2. **lodash.forkOwn** (not shown in the benchmark): This is another function from the Lodash library that iterates over an object, similar to `_.each`. It's not used in this specific benchmark. **Special JS Feature/Syntax** The benchmark does not explicitly use any special JavaScript features or syntax beyond what's mentioned above. However, it does take advantage of modern features like for...of loops and the built-in `Object.entries()` method. In summary, the benchmark is comparing four approaches to iterate over an object: * Lodash (`_.each` and `_map`) * Built-in `Object.entries` with a for loop * Built-in `Object.entries` with a for...of loop * Built-in `forEach` Each option has its own strengths and weaknesses, and the choice of approach depends on the specific use case and performance requirements.
Related benchmarks:
Loop over object: lodash vs Object.entries
Loop over object: lodash vs Object.entries fork by d9k 2
Loop over object: lodash vs Object.entries and Object.keys
Loop over object: lodash vs Object.entries [2]
Comments
Confirm delete:
Do you really want to delete benchmark?