Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
AsADqw
(version: 0)
Comparing performance of:
Underscore each vs Lodash each vs JS forEach
Created:
3 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 type="text/javascript"> window.lodash = _; _ = null; </script> <script src='https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.9.1/underscore-min.js'></script> <script type="text/javascript"> window.underscore = _; _ = null; </script>
Script Preparation code:
var obj1 = [...Array(10000).keys()]
Tests:
Underscore each
underscore.each(obj1, obj => { console.log(obj) });
Lodash each
lodash.each(obj1, obj => { console.log(obj) });
JS forEach
obj1.forEach(obj => { console.log(obj) })
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Underscore each
Lodash each
JS forEach
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 benchmark definitions and test cases. **Benchmarking Purpose** The goal of this benchmark is to compare the performance of three different approaches for iterating over an array in JavaScript: 1. **Underscore.js**: A functional programming library that provides a set of helper functions for tasks like iterating over arrays. 2. **Lodash**: Another popular utility library that includes a `each` function similar to Underscore.js. 3. **Native JavaScript (`forEach`)**: Using the built-in `forEach` method on an array. **Options Compared** The three options are compared in terms of their execution time, measured in executions per second (FPS). **Pros and Cons of Each Approach** 1. **Underscore.js (`each` function)**: * Pros: More concise and expressive code, often preferred for its readability. * Cons: External dependency on Underscore.js library, may incur additional overhead due to library loading and parsing. 2. **Lodash (`each` function)**: * Pros: Similar benefits as Underscore.js, with the added benefit of being a well-established library with extensive documentation. * Cons: Additional external dependency on Lodash library, same potential overhead as Underscore.js. 3. **Native JavaScript (`forEach`)**: * Pros: Fastest execution time due to its native implementation, no additional dependencies or overhead. * Cons: Code may become less concise and more verbose, especially for complex iterations. **Library and Syntax** In the provided test case, both Underscore.js and Lodash are used. They provide a `each` function that takes an array and a callback function as arguments. The callback function is called with each element of the array as an argument. The syntax for calling the `each` function is: ```javascript array.each(callback, [context]) ``` The `callback` function is expected to take two arguments: the current element being processed, and the original array (optional). **Other Considerations** * The benchmark measures executions per second (FPS), which provides a good indication of performance. * The test cases use a large array of 10,000 elements for demonstration purposes. * The benchmark results are based on data from Chrome 103 running on Linux. **Alternatives** If you need to compare the performance of other iteration methods in JavaScript, some alternatives include: 1. `map()`, `reduce()`, and `filter()` - These array methods provide more concise code than traditional for loops but may incur additional overhead. 2. `for` loop with a traditional index variable - This approach is often slower than using an array method like `forEach`. 3. Other libraries or frameworks that provide iteration utilities, such as Ramda or Liskelmann. Keep in mind that the performance differences between these alternatives can be significant, depending on the specific use case and hardware.
Related benchmarks:
Equals vs underscore vs lodash
Equals vs underscore vs lodash part 2
Underscore find vs Lodash find1
Underscore equal vs Lodash equal vs ===
Comments
Confirm delete:
Do you really want to delete benchmark?