Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Array.prototype.forEach vs _.each vs jquery each
(version: 0)
Compare the new ES6 spread operator with the traditional concat() method
Comparing performance of:
Array.prototype.forEach vs lodash each vs Jquery each
Created:
6 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.core.js"></script> <script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js'></script>
Tests:
Array.prototype.forEach
var params = [ "hello", true, 7 ]; var index = 0; params.forEach(param => index++);
lodash each
var params = [ "hello", true, 7 ]; var index = 0; _.each(params, param => index++);
Jquery each
var params = [ "hello", true, 7 ]; var index = 0; $.each(params, param => index++);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Array.prototype.forEach
lodash each
Jquery each
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36
Browser/OS:
Chrome 128 on Linux
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Array.prototype.forEach
86361056.0 Ops/sec
lodash each
3488025.5 Ops/sec
Jquery each
2829904.2 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
**Overview** The provided benchmark definition and test cases are designed to compare the performance of three different ways to iterate over an array in JavaScript: `Array.prototype.forEach`, Lodash's `_.each`, and jQuery's `$`. Each test case uses a small array with three elements and increments a variable for each iteration. **What is being tested** The benchmark is testing the execution speed of these three methods: 1. `Array.prototype.forEach`: A built-in JavaScript method that iterates over an array, executing a provided callback function for each element. 2. Lodash's `_.each`: A utility function from the Lodash library that provides a functional way to iterate over arrays and objects. 3. jQuery's `$`.each`: A method from the jQuery library that allows iterating over arrays using a callback function. **Options compared** The options being compared are: * `Array.prototype.forEach` * Lodash's `_.each` * jQuery's `$`.each **Pros and Cons of each approach:** 1. **`Array.prototype.forEach`**: * Pros: + Built-in JavaScript method, no additional library required. + Simple to use and understand. + Provides a clear way to iterate over arrays with a callback function. * Cons: + May be slower than optimized libraries due to the overhead of the built-in method. 2. **Lodash's `_.each`**: * Pros: + Part of a widely used and well-maintained library (Lodash). + Provides additional features, such as support for arrays with multiple lengths. + Can be optimized for performance. * Cons: + Requires including an additional library. 3. **jQuery's `$`.each`**: * Pros: + Part of a widely used and well-maintained library (jQuery). + Provides additional features, such as support for arrays with multiple lengths. + Can be optimized for performance. * Cons: + Requires including an additional library. **Library usage** In the benchmark code, Lodash's `_.each` is used to iterate over the array. The `$.each` method from jQuery is also used, but it requires including the jQuery library in the HTML header. **Special JS feature or syntax** There are no special JavaScript features or syntaxes being tested in this benchmark. The focus is on comparing the performance of three different iteration methods. **Other alternatives** If not using `Array.prototype.forEach`, other alternatives for iterating over arrays could include: * Using `for` loops * Utilizing `forEach`-like methods from other libraries (e.g., Ramda) * Implementing custom iteration logic However, these alternatives are not included in the benchmark.
Related benchmarks:
Array.prototype.concat vs spread operator sans jquery
Array.prototype.concat vs spread operator (minus jquery)
Array.prototype.concat vs spread operator (withouth JQuery)
Array.prototype.concat vs spread operator (jquery removed)
Array.prototype.concat vs spread without JQuery
Comments
Confirm delete:
Do you really want to delete benchmark?