Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash vs native (filter)
(version: 0)
Comparing performance of:
_ vs .f vs for
Created:
one year ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="lodash.js"></script>
Script Preparation code:
var array = [] for (let i = 0; i < 10000; i++) { array.push({ value: i }) }
Tests:
_
_.filter(array, (item) => { return item.n > 5000 })
.f
array.filter((item) => { return item.n > 5000 })
for
const _filter = ( collection, filterCallback, ) => { let index = 0 const result = [] for (const item of collection) { if (filterCallback(item, index, collection)) { result.push(item) } index++ } return result } _filter(array, (item) => { return item.n > 5000 })
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
_
.f
for
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/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36
Browser/OS:
Chrome 124 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
_
20504.5 Ops/sec
.f
82671.7 Ops/sec
for
131899.8 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down what's being tested in this benchmark. **Script Preparation Code** The script preparation code is responsible for setting up the test environment. In this case, it creates an array of 10,000 objects with a `value` property and pushes them onto the array using a `for` loop. This creates a large dataset that will be used to test various filter operations. **Html Preparation Code** The HTML preparation code includes a script tag that loads the Lodash library. This is important because it allows the benchmark to use Lodash's implementation of the `filter()` function. **Benchmark Test Cases** There are three benchmark test cases: 1. **Lodash `_` (underscore)** * The benchmark definition uses the Lodash `filter()` function, passing in the array as the first argument and a callback function that returns `true` if the item's `n` property is greater than 5000. * This test case is likely using Lodash's optimized implementation of the filter function, which is written in native code and has been tested for performance. 2. **Native `.f`** * The benchmark definition uses a standard JavaScript array method, `filter()`, with a similar callback function as above. * This test case is testing the native implementation of the filter function, which may not be as optimized as Lodash's version. 3. **Custom "for" loop implementation** * The benchmark definition uses a custom implementation of the filter function that iterates over the array using a `for` loop and checks each item against the callback function. * This test case is testing a custom implementation of the filter function, which may not be as efficient or optimized as the Lodash or native implementations. **Pros and Cons** Here are some pros and cons for each approach: 1. **Lodash `_`** * Pros: Optimized implementation, likely to be faster than native implementation. * Cons: Requires loading an external library (Lodash). 2. **Native `.f`** * Pros: No additional dependencies required, simple implementation. * Cons: May not be optimized for performance, may be slower than Lodash implementation. 3. **Custom "for" loop implementation** * Pros: Control over the implementation, can potentially optimize for specific use cases. * Cons: Requires manual optimization and testing to ensure it's competitive with other implementations. **Library and Syntax** The benchmark is using Lodash, a popular JavaScript library that provides a collection of functional programming helpers. The `filter()` function is a key part of Lodash, and its implementation is being tested here. There are no special JS features or syntax used in this benchmark. **Alternatives** Other alternatives for implementing the filter function include: * Other libraries like Ramda or Mocha * A pure JavaScript implementation without any external dependencies * A compiled JavaScript implementation using tools like Webpack or Babel Overall, the benchmark is testing the performance of different implementations of the filter function, including a native implementation, a Lodash implementation, and a custom implementation. The results can help users understand the trade-offs between these different approaches and choose the best one for their specific use case.
Related benchmarks:
Array.prototype.filter vs Lodash filter
Array.prototype.filter vs Lodash 4.17.5 filter
Array.prototype.filter vs Lodash filter Clone Test
Array.prototype.filter vs Lodash filter bumped to million
Array.prototype.filter vs Lodash filter for ~10000
Comments
Confirm delete:
Do you really want to delete benchmark?