Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
test-lodash-and-native-methods
(version: 0)
Test
Comparing performance of:
Lodash vs Native
Created:
6 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src='https://cdn.jsdelivr.net/npm/lodash@4.17.10/lodash.min.js'></script>
Script Preparation code:
var value = _.times(1000000).map(x => ({ a: x }));
Tests:
Lodash
_.each(value, function(v,i) { v.a += i })
Native
value.forEach(function(v,i) { v.a += i })
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Lodash
Native
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/135.0.0.0 Safari/537.36
Browser/OS:
Chrome 135 on Linux
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Lodash
276.5 Ops/sec
Native
327.1 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down what's being tested in this benchmark. **Overview** The test compares the performance of two approaches: using the `lodash` library and native JavaScript methods. **What is being compared?** Two individual test cases are being compared: 1. **Lodash**: The benchmark uses the `_.each()` function from the `lodash` library to iterate over an array and increment each element's `a` property by its index. 2. **Native**: The benchmark uses native JavaScript methods, specifically `forEach()`, to achieve the same result. **Options compared** The two approaches are being compared: * **Lodash**: Using a third-party library (`lodash`) to perform the iteration and transformation. * **Native**: Using only built-in JavaScript features (no external libraries) to perform the iteration and transformation. **Pros and Cons of each approach:** **Lodash:** Pros: * Easier to read and write, as it abstracts away the iteration logic. * Can be useful for complex transformations or when working with legacy code that relies on `lodash`. Cons: * Introduces an additional dependency (the `lodash` library) which may not be present in all environments. * May have overhead due to the library's presence. **Native:** Pros: * No external dependencies, making it more suitable for environments where `lodash` is not available or desired. * Can optimize performance by avoiding the library's overhead. Cons: * Requires more manual effort to write and maintain, especially for complex iterations. * May be less readable or maintainable for some developers. **Library: Lodash** Lodash (`_`) is a popular JavaScript utility library that provides a collection of functional programming helpers. In this benchmark, `_.each()` is used to iterate over the array and perform an operation on each element. **Special JS feature or syntax** There are no special features or syntaxes being used in this benchmark. It's standard JavaScript with some minor optimizations for performance. **Other alternatives** If you want to optimize performance without relying on a third-party library, you could consider using native JavaScript methods like: * `forEach()` * `map()` * `filter()` * `reduce()` These methods are part of the ECMAScript standard and can be used to achieve similar results. However, they may require more manual effort to write and maintain. In summary, the benchmark is testing the performance difference between using a third-party library (`lodash`) and native JavaScript methods for simple iteration tasks. The `Lodash` approach introduces some convenience but also adds overhead, while the `Native` approach provides better performance but requires more manual effort.
Related benchmarks:
Loop over object: lodash vs Object.entries fork by d9k 2
Loop over object: lodash vs Object.entries fork by d9k 3
Lodash reduce vs native
big lodash vs nativejs foreach
Array.prototype.every vs Lodash every()
Comments
Confirm delete:
Do you really want to delete benchmark?