Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Native vs Lodash asda
(version: 0)
Comparing performance of:
Native vs Lodash
Created:
3 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var max1 = 100000; // 100,000 (100 Thousand) var max2 = 10000000; // 10,000,000 (10 Million) var max3 = 100000000; // 100,000,000 (100 Million) var dataset = [...Array(max1)].map((_, index) => { const res = { id: index }; const prop1 = index % 2 === 0 ? { prop1: 1 } : {}; const prop2 = index % 10 === 0 ? { prop2: true } : {}; return { ...res, ...prop1, ...prop2 }; }); var toCreate = []; var toUpdate = []; var toDelete = [];
Tests:
Native
for (const data of dataset) { if (_.has(data, 'prop1')) { toCreate.push(data); continue; } if (_.has(data, 'prop2')) { toDelete.push(data); continue; } toUpdate.push(data); }
Lodash
const [toDelete, toUpsert] = _.partition(dataset, (dp) => _.has(dp, 'isDelete'), ); const [toUpdate, toCreate] = _.partition(toUpsert, (dp) => _.has(dp, 'id'), );
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Native
Lodash
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):
I'll break down the provided benchmark definition and test cases, explaining what's being tested, the pros and cons of different approaches, and other considerations. **Benchmark Definition** The benchmark is comparing two JavaScript libraries: Native (i.e., built-in JavaScript) and Lodash. The benchmark focuses on filtering a large dataset to create, update, or delete objects based on specific conditions. **Script Preparation Code** The script prepares an array of 100,000 elements, where each element represents a data point with an `id` property. Some data points have additional properties (`prop1` and `prop2`) that are set based on their index in the array. The script also initializes three arrays: `toCreate`, `toUpdate`, and `toDelete`. **Html Preparation Code** There is no HTML preparation code provided, which means that this benchmark only focuses on JavaScript performance. **Test Cases** The benchmark consists of two test cases: 1. **Native**: This test case uses the built-in JavaScript `for...of` loop to iterate over the dataset and filter it based on the presence of `prop1` and `prop2`. The resulting objects are pushed into three separate arrays: `toCreate`, `toUpdate`, and `toDelete`. 2. **Lodash**: This test case uses Lodash's `_.has()` function to check for the presence of `prop1` and `prop2` in each data point. The resulting objects are also pushed into the same three arrays as the Native test case. **Options Compared** The two test cases compare the performance of: * Built-in JavaScript vs Lodash's filtering capabilities * Manual looping vs using a library function to filter data **Pros and Cons** Here's a brief summary of the pros and cons of each approach: **Native (Built-in JavaScript)** Pros: * No external dependency on a library * Simple and straightforward implementation Cons: * May be slower than optimized libraries like Lodash * Requires manual looping, which can be error-prone and less efficient for large datasets **Lodash** Pros: * Optimized filtering algorithm that's likely to be faster than built-in JavaScript * Allows for a more concise and readable codebase Cons: * External dependency on the Lodash library * May introduce additional overhead due to function calls and other dependencies **Other Considerations** * The benchmark uses a relatively small dataset (100,000 elements), which may not accurately represent real-world performance. * The `for...of` loop used in the Native test case is likely to be faster than a manual loop using traditional JavaScript indexing (`i` variable). * Lodash's filtering algorithm is designed to work efficiently with large datasets and provides features like caching and memoization, which are not present in built-in JavaScript. **Alternatives** Other alternatives for filtering large datasets in JavaScript include: * Using a library like React's `useMemo()` or `useCallback()`, which provide optimized memoization mechanisms * Utilizing modern JavaScript features like `flatMap()` or `filter()` with array methods, which can be more concise and efficient than traditional looping approaches.
Related benchmarks:
lodash vs for-of vs forEach5453
lodash vs for-of vs forEach vs map v2
Lodash vs reduce Map()
lodash mapValues vs vanilla Object.keys foreach vs lodash reduce
lodash map vs native map wraig0
Comments
Confirm delete:
Do you really want to delete benchmark?