Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash.js vs Native kdsjbfkdsjnfdjsknfkjd
(version: 0)
Comparing performance of:
Native vs Lodash.js
Created:
3 years ago
by:
Registered User
Jump to the latest result
HTML Preparation code:
<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.15/lodash.min.js"></script>
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.js
const create = dataset.filter((dp) => _.has(dp, 'prop1')); const deleted = dataset.filter((dp) => _.has(dp, 'prop2')); const update = dataset.filter((dp) => !_.has(dp, 'prop1') && !_.has('prop2'));
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Native
Lodash.js
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 dive into the explanation of the provided benchmark. **Benchmark Definition** The benchmark is testing two approaches to filter an array of objects: using native JavaScript and using the Lodash library. **Options Compared** The options being compared are: 1. Native JavaScript approach 2. Lodash.js library approach **Pros and Cons** Native JavaScript approach: Pros: * No external dependency (no additional download or import needed) * Faster execution, as it doesn't involve an extra layer of indirection * More control over the execution flow Cons: * Can be more verbose, requiring explicit filtering logic * May have performance issues if not implemented optimally Lodash.js library approach: Pros: * More concise and readable code * Can be optimized for performance by Lodash's internal algorithms * Easier to maintain and update Cons: * Requires an external dependency (additional download or import needed) * May introduce overhead due to the extra layer of indirection * Less control over execution flow **Library: Lodash.js** Lodash is a popular JavaScript utility library that provides a set of functions for working with arrays, objects, and other data structures. In this benchmark, it's being used to filter an array of objects based on the presence of certain properties. **Special JS Feature/Syntax** There are no special JavaScript features or syntaxes mentioned in the benchmark definition or test cases. The code uses standard JavaScript syntax and does not rely on any proprietary or experimental features. **Other Alternatives** If you're interested in exploring other approaches, here are a few alternatives: * Using `Array.prototype.filter()` method directly: This approach is similar to the native JavaScript approach but relies on the built-in `filter` method. It's concise and efficient. * Using `Array.prototype.reduce()` method with an accumulator function: This approach can be used to filter an array by reducing it to a new array containing only the desired elements. **Benchmark Preparation Code** The preparation code sets up the benchmarking environment: * It defines three variables, `max1`, `max2`, and `max3`, which represent the number of iterations for each test case. * It creates a dataset using an array comprehension and mapping function. * It initializes empty arrays, `toCreate`, `toUpdate`, and `toDelete`, to store the filtered data. **Individual Test Cases** The two test cases are: 1. **Native**: This test case uses the native JavaScript approach with explicit filtering logic. 2. **Lodash.js**: This test case uses Lodash.js library to filter an array of objects based on the presence of certain properties. Both test cases execute at different rates, indicating that the native JavaScript approach is generally faster than using the Lodash.js library.
Related benchmarks:
lodash vs for-of vs forEach5453
Loop over object: lodash vs Object.entries fork by d9k 2
Loop over object: lodash vs Object.entries fork by d9k 3
lodash vs for-of vs forEach vs map v2
Lodash vs reduce Map()
Comments
Confirm delete:
Do you really want to delete benchmark?