Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Max value: Lodash vs native array functions
(version: 0)
Compare native
Comparing performance of:
Native array functions vs Lodash
Created:
6 years ago
by:
Registered User
Jump to the latest result
HTML Preparation code:
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.10/lodash.min.js'></script>
Script Preparation code:
var values = Array(10000).fill(null).map((x, a) => ({number: a})); var filterFn = x => !(x.number % 5); var mapFn = x => x.number; var reduceFn = (a, b) => a > b ? a : b;
Tests:
Native array functions
const result1 = values.filter(filterFn).map(mapFn).reduce(reduceFn); console.log(result1);
Lodash
const result2 = _(values).filter(filterFn).map(mapFn).max(); console.log(result2);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Native array functions
Lodash
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.1 Safari/605.1.15
Browser/OS:
Safari 18 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Native array functions
37549.9 Ops/sec
Lodash
36757.1 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the benchmark and explain what is being tested. **Benchmark Definition** The benchmark is comparing two approaches: 1. **Native Array Functions**: Using built-in JavaScript array methods to filter, map, and reduce the `values` array. 2. **Lodash**: Utilizing the Lodash library to perform the same operations on the `values` array. **Options Compared** The options being compared are: * **Filtering**: Using a callback function (`filterFn`) to exclude elements from the filtered array (native) vs using the `filter()` method provided by Lodash (`_(values).filter(filterFn)`). * **Mapping**: Applying a transformation to each element of the filtered array using a callback function (`mapFn`) (native) vs using the `map()` method provided by Lodash (`_(values).map(mapFn)`). * **Reducing**: Finding the maximum value in the mapped array using a callback function (`reduceFn`) (native) vs using the `max()` method provided by Lodash (`_(values).max()`). **Pros and Cons of Each Approach** **Native Array Functions** Pros: * Built-in, so no additional library is required. * May be faster since it's native code. * Can be more efficient for large datasets. Cons: * Requires manual implementation of the filtering, mapping, and reducing operations. * Can be less readable and maintainable compared to using a library. **Lodash** Pros: * Provides pre-built functions for common operations like filtering, mapping, and reducing. * Can simplify code and make it more readable. * Often faster than native implementations due to optimized C++ code. Cons: * Requires an additional library to be included in the project. * May introduce overhead due to the need to import the library. * Can be slower compared to native implementations for very large datasets. **Other Considerations** * **Caching**: Both approaches can benefit from caching the results of intermediate operations. However, Lodash provides a `memoize()` function that can help with this. * **Parallelization**: If you need to measure performance across multiple threads or processes, you'll want to consider using Web Workers or a similar approach. **Library: Lodash** Lodash is a popular JavaScript utility library that provides a collection of functions for common tasks like filtering, mapping, reducing, and more. The `filter()`, `map()`, and `max()` methods mentioned in the benchmark are part of Lodash's API. By using these methods, developers can simplify their code and focus on the logic of their application rather than rewriting manual implementations. **Special JS Feature or Syntax** There is no special JavaScript feature or syntax used in this benchmark. However, note that some modern browsers support features like `async/await` and `class` for handling promises, which could be relevant when writing tests for other benchmarks. **Other Alternatives** If you need to compare performance of native array methods against Lodash's implementation, here are a few alternatives: * **Underscore.js**: Another popular utility library that provides similar functions as Lodash. * **Array.prototype.forEach()`: Using the `forEach()` method instead of `filter()`, `map()`, or `reduce()` for the operations being compared. * **Custom implementations**: Writing your own custom implementations using vanilla JavaScript, which can help to understand the underlying performance characteristics of each approach.
Related benchmarks:
Array.prototype.filter vs Lodash filter
Array.prototype.filter vs Lodash filter (Even Numbers)
Array.prototype.filter vs Lodash 4.17.5 filter
Lodash.filter vs Lodash.without
Lodash filter VS native filter (with Lodash actually loaded)
Comments
Confirm delete:
Do you really want to delete benchmark?