Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
lodash.forOwn vs for..in
(version: 0)
Comparing performance of:
lodash.each vs native
Created:
5 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="https://cdn.jsdelivr.net/lodash/4.16.0/lodash.min.js"></script>
Script Preparation code:
var arrayValue = [{a: 30310}, {b: 100303}, {c: 3040494}] var objectValue = { a: 30310, b: 100303, c: 3040494}
Tests:
lodash.each
_.forOwn(objectValue, function(v,i) {})
native
for(var k in objectValue) { var v = objectValue[k]; }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
lodash.each
native
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
10 months ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.5 Safari/605.1.15
Browser/OS:
Safari 18 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
lodash.each
31003190.0 Ops/sec
native
102259344.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark and explain what is being tested. **Benchmark Overview** The benchmark compares two approaches for iterating over an object: `_.forOwn` from Lodash and the native `for...in` loop. The test case uses two JavaScript objects, `arrayValue` and `objectValue`, which contain similar properties with different values. **Options Compared** Two options are being compared: 1. **Lodash's `_forOwn` method**: This is a utility function that iterates over an object using a provided callback function. It's designed to iterate over the keys of the object, not its values. 2. **Native `for...in` loop**: This is a built-in JavaScript syntax for iterating over the properties of an object. **Pros and Cons** **Lodash's `_forOwn` method** Pros: * Well-tested and widely used, making it a reliable choice * Provides a convenient way to iterate over objects without worrying about key order Cons: * Requires Lodash library inclusion, which can add extra overhead * May not be the best choice for very large or sparse datasets due to its performance characteristics **Native `for...in` loop** Pros: * Fast and efficient, as it's a built-in JavaScript syntax * Does not require any external libraries Cons: * Can be slower than Lodash's `_forOwn` method for some scenarios (more on this later) * May have issues with key order or undefined values, depending on the use case **Other Considerations** The test case uses `_.forOwn` and `for...in` loops to iterate over an object. The Lodash library is included in the HTML preparation code, making it a self-contained test. **Special JS Features or Syntax** There are no special JavaScript features or syntax used in this benchmark that require explanation. **Library Used** Lodash (specifically, its `forOwn` method) is used in this benchmark. The purpose of Lodash is to provide a set of utility functions that make common programming tasks easier. In this case, the `_forOwn` method provides a convenient way to iterate over objects without worrying about key order. **Benchmark Test Case** The test cases are: 1. `lodash.each`: This test case uses the Lodash `_forOwn` method to iterate over an object. 2. `native`: This test case uses the native `for...in` loop to iterate over an object. **Alternative Approaches** Other alternative approaches for iterating over objects include: * Using `Object.keys()` and `forEach()` * Using a simple `for...of` loop (not applicable in this benchmark, as it's using `for...in`) * Using a library like `loop-queue` or `async-map` Keep in mind that the best approach depends on the specific use case and performance requirements.
Related benchmarks:
lodash.values vs Object.values
lodash.forOwn vs Native.forEach
Performance of Object.values(obj) vs_.values() vs for-in to extract values from an object
obj.ent vs forown
Comments
Confirm delete:
Do you really want to delete benchmark?