Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Iterating Lodash Entries vs Object.entries (10,000 entries)
(version: 0)
Comparing performance of:
Object.entries vs lodash.entries
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 Preparation code:
window.obj = Array.from({length: 10_000}).reduce((acc, _, i) => { return {...acc, [`key${i}`]: `val{i}`} }, {})
Tests:
Object.entries
let count = 0 for (const [key, value] of Object.entries(obj)) { count++; }
lodash.entries
let count = 0 for (const [key, value] of _.entries(obj)) { count++; }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Object.entries
lodash.entries
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 provided JSON benchmark definition and test cases. **Benchmark Definition** The benchmark is comparing the performance of two approaches to iterate over the entries of an object: 1. **`Object.entries(obj)`**: This method returns an array of key-value pairs for every entry in the object `obj`. It uses a built-in JavaScript feature, which is supported by all modern browsers and engines. 2. **`_.entries(obj)`**: This method is part of the Lodash library (version 4.17.5) and returns the same array of key-value pairs as `Object.entries()`. The underscore prefix refers to the Lodash alias. **Script Preparation Code** The script preparation code generates a sample object with 10,000 entries, where each entry has a unique key and value. ```javascript window.obj = Array.from({length: 10_000}).reduce((acc, _, i) => { return {...acc, [`key${i}`]: `val{i}`} }, {}) ``` This code uses the spread operator (`...`) to create a new object with each entry having a unique key-value pair. **Html Preparation Code** The HTML preparation code includes the Lodash library (version 4.17.5) via an external script tag: ```html <script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script> ``` This ensures that the Lodash library is available for use in the benchmark tests. **Test Cases** The test cases are defined as follows: 1. **`Object.entries`**: This test case uses the built-in JavaScript method `Object.entries()` to iterate over the entries of the object. 2. **`.entries(obj)`**: This test case uses the Lodash library's `_.entries()` function to iterate over the entries of the object. **Options Compared** The benchmark compares two options: 1. Using the built-in JavaScript method `Object.entries()`. 2. Using the Lodash library's `_.entries()` function. **Pros and Cons** Here are some pros and cons of each approach: * **`Object.entries()`**: + Pros: Built-in JavaScript feature, no external dependency. + Cons: May have performance overhead due to the creation of an array. * **`.entries(obj)`**: + Pros: Faster execution speed compared to `Object.entries()`, thanks to Lodash's optimized implementation. + Cons: Requires an external dependency (Lodash library) and may not be supported in older browsers. **Library: Lodash** The Lodash library is a popular utility belt for JavaScript developers, providing various functions for tasks such as array manipulation, object iteration, and more. In this benchmark, the `_.entries()` function is used to iterate over the entries of an object. **Special JS Feature/Syntax** There are no special JavaScript features or syntax mentioned in this benchmark. Both tests use standard JavaScript methods and Lodash library functions. **Alternatives** Some alternatives for iterating over object entries include: * Using a for...in loop: `for (const key in obj) { ... }` * Using a for...of loop with Object.keys(): `for (const key of Object.keys(obj)) { ... }` * Using a custom implementation using Array.prototype.forEach() or other methods. Keep in mind that the performance differences between these alternatives may vary depending on the specific use case and browser/engine being used.
Related benchmarks:
Loop over object: lodash vs Object.entries
Loop over object: lodash vs Object.entries and Object.keys
Loop over object: lodash vs Object.entries vs Object.keys vs Object.values
Iterating Lodash Entries vs Object.entries
Comments
Confirm delete:
Do you really want to delete benchmark?