Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Underscore each v native object foreach
(version: 0)
Comparing performance of:
Underscore vs Native
Created:
2 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.9.0/underscore.js"></script>
Script Preparation code:
var data = {}; Array(10000).keys().forEach(function (i) { data[i] = i; });
Tests:
Underscore
var result = 0 _.each(data, (i) => {result += i})
Native
var result = 0 Object.values(data).forEach((i) => {result += i})
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Underscore
Native
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 years ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36 OPR/104.0.0.0
Browser/OS:
Opera 104 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Underscore
11266.4 Ops/sec
Native
42062.4 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the explanation of the provided benchmark. **Benchmark Purpose and Comparison** The benchmark is designed to compare two approaches for iterating over an object in JavaScript: using Underscore.js, a popular utility library, and the native `Object.values()` method. The goal is to determine which approach is faster and more efficient. **Options Compared** The comparison involves two options: 1. **Underscore.js**: A library that provides functional programming helpers, including iteration utilities. 2. **Native (Object.values())**: The built-in `Object.values()` method in JavaScript, which returns an array of a given object's own enumerable property values. **Pros and Cons** * **Underscore.js**: + Pros: Provides a familiar and intuitive API for iterating over objects, especially when working with functional programming principles. + Cons: Introduces an additional library dependency, which might not be desirable in all scenarios. Additionally, since Underscore is a separate library, the overhead of loading it can impact performance. * **Native (Object.values())**: + Pros: No additional library dependency means less overhead and faster execution time. + Cons: The API might be less familiar to developers who are not comfortable with functional programming concepts or modern JavaScript features. **Library Used: Underscore.js** Underscore.js is a popular utility library that provides various helper functions for tasks such as array manipulation, object iteration, and more. In this benchmark, the `_.each()` method is used to iterate over the `data` object. **Special JS Feature/ Syntax: None** This benchmark does not rely on any special JavaScript features or syntax beyond what's already included in modern browsers. **Other Alternatives** If you're looking for alternative approaches to iterating over objects, consider: * **For...in**: A built-in loop that iterates over an object's own enumerable properties. * **For...of**: A more modern approach using the `for...of` loop with the `Symbol.iterator` method to iterate over arrays and other iterable objects. These alternatives might not be as efficient or convenient as the native `Object.values()` method, but they can still provide viable solutions for specific use cases. Keep in mind that the choice of iteration method often depends on the context and requirements of your application. Understanding the trade-offs between different approaches is essential for writing efficient and effective code.
Related benchmarks:
Underscore vs Array functions
Loop over object: lodash vs Object.entries vs Object.keys vs Object.values vs for of vs for in vs keys for of
Underscore each vs native foreach
Underscore each vs native object foreach
Comments
Confirm delete:
Do you really want to delete benchmark?