Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Loop over object: lodash vs Object.entries vs Object.values vs Object.keys (lodash 4.17.15)
(version: 1)
Comparing performance of:
lodash.map vs Object.entries.map vs vanilla for-loop w/ Object.entries vs lodash.forEach vs Object.values vs Object.keys
Created:
4 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.15/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.map
_.map(obj, function(v, k) {})
Object.entries.map
Object.entries(obj).map(function([k, v]) {})
vanilla for-loop w/ Object.entries
const entries = Object.entries(obj); for (let i = 0; i < entries.length; i++) { const [k, v] = entries[i]; }
lodash.forEach
_.forEach(obj, function(v, k) {})
Object.values
Object.values(obj).forEach(function(val, index) { const v = val; });
Object.keys
Object.keys(obj).forEach(function(key, index) { const k = key; });
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (6)
Previous results
Fork
Test case name
Result
lodash.map
Object.entries.map
vanilla for-loop w/ Object.entries
lodash.forEach
Object.values
Object.keys
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 what's being tested on MeasureThat.net. **Benchmark Definition** The benchmark is designed to compare the performance of different approaches for iterating over an object in JavaScript: 1. `lodash` (Lodash) methods: `map`, `forEach` 2. Vanilla JavaScript methods: `Object.entries` with a `for` loop, `Object.values` with a `forEach` loop, and `Object.keys` with a `forEach` loop **Options being compared** Each option is being tested for its performance using the following metrics: * Number of executions per second (ExecutionsPerSecond) The options being compared are: 1. `lodash.map` 2. `lodash.forEach` 3. Vanilla JavaScript methods: * `Object.entries.map` * `Object.values.forEach` * `Object.keys.forEach` **Pros and Cons** Here's a brief summary of the pros and cons of each approach: 1. **Lodash methods (map, forEach)** * Pros: More concise code, often more readable * Cons: May incur overhead due to function calls and closure creation 2. **Vanilla JavaScript methods (Object.entries, Object.values, Object.keys with for loop)** * Pros: No external dependencies, no potential overhead from closures * Cons: Code can be less concise and more verbose **Library usage** In this benchmark, the `lodash` library is being used to provide a set of utility functions that are commonly used in JavaScript development. The `lodash` methods (`map`, `forEach`) use closures to iterate over the object, which can introduce additional overhead. The vanilla JavaScript methods (using `Object.entries`, `Object.values`, and `Object.keys`) do not rely on closures, making them potentially more efficient. **Special JS features or syntax** There are no special JavaScript features or syntaxes being used in this benchmark, such as async/await, promises, or ES6+ classes. **Other alternatives** Some other alternatives to Lodash for iterating over objects could include: * `Array.prototype.forEach` * `Array.prototype.map` * Custom looping mechanisms using `for` loops or `while` loops * Other libraries that provide similar functionality (e.g., underscore.js) Overall, the benchmark is designed to help developers understand the performance implications of different approaches when iterating over objects in JavaScript.
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 [2]
Loop over object: lodash vs Object.entries vs Object.keys vs Object.values
Comments
Confirm delete:
Do you really want to delete benchmark?