Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
lodash.filter and native.filter
(version: 0)
Comparing performance of:
native filter vs lodash filter
Created:
2 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script>
Script Preparation code:
var testCopy = null; var testArray = [{ id: 1, description: 'Random description.', testDate: new Date(), testBoolean: true, testObject: { testString: 'test string', testNumber: 12345 }, testArray: [{ myName: 'test name', myNumber: 123245 }] },{ id: 2, description: 'Random description.', testNumber: 123456789, testBoolean: true, testObject: { testString: 'test string', testNumber: 12345 }, testArray: [{ myName: 'test name', myNumber: 123245 }] }];
Tests:
native filter
testCopy = testArray.filter(o => { if(o.id != 2) { o.description = 'test'; return o; } });
lodash filter
testCopy = _.filter(testArray, function(o) { if(o.id != 2) { o.description = 'test'; return o; } });
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
native filter
lodash filter
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 provided benchmark definition and explain what is tested, compared, and other considerations. **Benchmark Definition** The benchmark measures the performance of two approaches: native JavaScript filtering and Lodash filtering on an array of objects. The test case uses a predefined script preparation code that creates an array of objects with various properties and filters out one specific object based on its `id` property. **What is tested?** * Native JavaScript filtering using a callback function * Lodash filtering using the `_filter` method **Options compared** Two options are being compared: 1. **Native JavaScript filtering**: This approach uses a built-in JavaScript feature to filter the array. The callback function takes an object as an argument and returns `true` if it should be included in the filtered array. 2. **Lodash filtering**: This approach uses a third-party library (Lodash) that provides a more concise way to filter arrays. **Pros and cons of each approach** * Native JavaScript filtering: + Pros: Built-in, no additional dependencies required + Cons: Can be slower due to the need for a callback function evaluation * Lodash filtering: + Pros: Concise syntax, often faster due to optimized implementations + Cons: Requires an additional library dependency **Other considerations** * **Loop unrolling**: Some modern JavaScript engines, like V8 (used by Chrome), can optimize loop unrolling for native filtering. This might improve performance. * **Cache efficiency**: Lodash filtering might have better cache locality due to the optimized `_filter` method implementation. **Library and its purpose (Lodash)** Lodash is a popular utility library that provides various functions for tasks like array manipulation, string manipulation, and more. In this benchmark, the `_filter` function is used to filter an array of objects based on a given condition. **Special JS feature or syntax** There are no special features or syntaxes mentioned in the provided code snippets. However, it's worth noting that some JavaScript engines, like V8, have specific optimizations for certain features, such as `for...of` loops or arrow functions. **Alternatives** Other alternatives to Lodash filtering could include: * Using a different library (e.g., Ramda) with similar functionality * Implementing the filtering logic manually without a library * Using a different JavaScript engine or version that might have optimized implementations of the `_filter` method
Related benchmarks:
Filter: Lodash vs Native
lodash filter vs array.filter
lodash vs es6 in filter method
Array.prototype.filter vs Lodash filter (1)
Filter: Lodash 2 vs Native
Comments
Confirm delete:
Do you really want to delete benchmark?