Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash vs Js Native
(version: 0)
Comparing performance of:
lodash.forEach vs Js Native
Created:
4 years ago
by:
Registered User
Jump to the latest result
HTML Preparation code:
<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.21/lodash.min.js"></script>
Script Preparation code:
var values = [{ a: 30000 }, { b: 300000 }, { c: 3000000 }]
Tests:
lodash.forEach
var count = 0; _.forEach(values, function(v,i) { if (v.a != null) { count++; } })
Js Native
var count = 0; for (var i = 0; i < values.length; i++) { if (values[i].a != null) { count++; } }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
lodash.forEach
Js Native
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 years ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36
Browser/OS:
Chrome 120 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
lodash.forEach
6661459.0 Ops/sec
Js Native
3865968.2 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the world of JavaScript microbenchmarks. **What is being tested?** The provided JSON represents two individual test cases for benchmarking the performance of Lodash and JavaScript native code on a specific task: iterating over an array to count elements with a null value in the "a" property. The test case uses a predefined array `values` containing three objects with varying values for the "a" property. **Options being compared** Two approaches are being compared: 1. **Lodash:** Using Lodash's `_forEach` function, which is a higher-order function that takes an iterator and a callback function as arguments. 2. **JavaScript Native:** Implementing a simple `for...of` loop to iterate over the array. **Pros and Cons of each approach:** 1. **Lodash:** * Pros: + Simplified code, as it provides a built-in `forEach` function with minimal boilerplate. + Easier to read and maintain, as it abstracts away low-level iteration details. * Cons: + Additional dependency on the Lodash library, which may introduce overhead. + Might lead to performance differences due to the indirection introduced by the higher-order function. 2. **JavaScript Native:** * Pros: + No additional dependencies or potential overhead. + Direct implementation of iteration logic, reducing complexity and potentially improving cache locality. * Cons: + Requires more code and manual iteration details, making it less readable and maintainable for some developers. **Library used** The Lodash library is being used in the benchmark. Lodash is a popular utility library that provides numerous functions for tasks such as array manipulation, string formatting, and event handling. In this case, the `_forEach` function is used to iterate over the `values` array. **Special JavaScript feature or syntax** None are mentioned explicitly in the provided code snippets. **Other alternatives** If you're interested in exploring alternative approaches, here are a few options: * **Array.prototype.forEach.call()**: Instead of using Lodash's `_forEach`, you could use the `call()` method to invoke the `forEach` function directly on the array prototype. * **For loops with callbacks**: You could implement a traditional `for...of` loop that uses callbacks for each iteration, similar to the JavaScript Native approach. * **Web workers or parallel execution**: If performance is critical, you might consider using web workers or parallel execution mechanisms to execute both Lodash and native code concurrently. These alternatives can provide interesting insights into how different approaches affect performance and may lead to further optimizations.
Related benchmarks:
lodash.values vs Object.values
big lodash vs nativejs foreach
Lodash tail vs native slice(1)
Lodash vs Native v3,0,0
JS ForEach Tests
Comments
Confirm delete:
Do you really want to delete benchmark?