Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash Vs Native JS
(version: 0)
Performance comparison
Comparing performance of:
Lodash vs Native
Created:
7 years ago
by:
Registered User
Jump to the latest result
HTML Preparation code:
<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.4/lodash.min.js"></script>
Script Preparation code:
var data = Array(1000000).fill({ filtering: true, mapping: 42 });
Tests:
Lodash
_.map(_.filter(data, 'filtering'), 'mapping')
Native
data.filter(({ filtering }) => filtering).map(({ mapping }) => mapping)
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:
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 JSON and explain what's being tested, compared, and its pros and cons. **Benchmark Definition** The benchmark is comparing the performance of two approaches: 1. **Lodash**: A popular JavaScript library that provides utility functions for various tasks, including array manipulation. 2. **Native JS**: The built-in JavaScript implementation without any external libraries. **Script Preparation Code** The script preparation code creates a large dataset (`data`) using an array comprehension: ```javascript var data = Array(1000000).fill({ filtering: true, mapping: 42 }); ``` This dataset is used as input for both benchmarking functions. **Html Preparation Code** An external library (Lodash) is included in the HTML file: ```html <script src="https://cdn.jsdelivr.net/npm/lodash@4.17.4/lodash.min.js"></script> ``` The `_.map` and `_.filter` functions from Lodash are used to process the dataset. **Individual Test Cases** There are two test cases: 1. **Lodash**: `_._map(_.filter(data, 'filtering'), 'mapping')` This function uses Lodash's `_.map` to apply a transformation to the filtered data. ```javascript // Lodash implementation: function _map(arr, cb) { return arr.map(cb); } // Filtered data: const filteredData = _.filter(data, 'filtering'); // Mapping: const mappedData = _.map(filteredData, 'mapping'); ``` 2. **Native JS**: `data.filter(({ filtering }) => filtering).map(({ mapping }) => mapping)` This function uses the built-in JavaScript array methods to filter and map the data directly. **Pros and Cons** * **Lodash (with external library)**: + Pros: Easier to read and write, especially for complex transformations. + Cons: Adds an extra dependency, potentially slower due to overhead of loading the library. * **Native JS (without external library)**: + Pros: No dependencies, faster execution. + Cons: More verbose and error-prone code. **Other Considerations** In this specific benchmark, the performance difference between Lodash and Native JS is significant. However, in other scenarios, the choice might depend on factors like: * Code readability vs. performance * Complexity of transformations * Project dependencies and ecosystem As for special JavaScript features or syntax used, none are explicitly mentioned in the provided code snippets. **Alternatives** Other alternatives to Lodash that can be used as a native implementation would include other popular libraries like: * `Array.prototype.map` and `Array.prototype.filter` * `reduce` method * Other utility functions from specific libraries (e.g., `lodash-es`, `ramda`)
Related benchmarks:
Filter-Map: Lodash vs Native (smaller array
Filter: Lodash 2 vs Native
Filter: Lodash vs Native - same filter
Map: Lodash vs Native
Map: Lodash vs Native JS
Comments
Confirm delete:
Do you really want to delete benchmark?