Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
f vs c
(version: 0)
Comparing performance of:
lodash filter vs lodash compact vs normal
Created:
7 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="https://cdn.jsdelivr.net/lodash/4.16.0/lodash.min.js"></script>
Script Preparation code:
var ops = [null, 1, 2, 3, 4, 5, null, null, null, 3, 4,5, 6, 34,341,2,2,2,1,212,21212,34,1,3112, null];
Tests:
lodash filter
_.filter(ops)
lodash compact
_.compact(ops)
normal
_.filter(op => !!op)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
lodash filter
lodash compact
normal
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 is tested in the benchmark. **Benchmark Overview** The benchmark measures the performance of three different approaches to filtering out null values from an array: using Lodash's `filter()` method, using Lodash's `compact()` method, and a custom implementation without any libraries (the "normal" approach). **Lodash Library** Lodash is a popular JavaScript utility library that provides various functions for common tasks such as array manipulation, string manipulation, and more. In this benchmark, we're focusing on two of its functions: `filter()` and `compact()`. * Lodash's `filter()` method returns a new array containing only the elements that pass the test implemented by the provided function. * Lodash's `compact()` method returns a new array with all falsey values removed from the original array. **Approach Comparison** Here's a brief overview of each approach, their pros and cons, and other considerations: 1. **Lodash `filter()` Method** * Pros: Easy to use, efficient (it uses a optimized V8 implementation). * Cons: Adds an extra dependency on Lodash. * Other consideration: The benchmark provides the Lodash library as a CDN reference in the HTML Preparation Code section, so it's easy to include and test. 2. **Lodash `compact()` Method** * Pros: Similar to `filter()`, but with a more focused approach (removing falsey values). * Cons: Similar to `filter()`, adds an extra dependency on Lodash. 3. **Custom "normal" Approach** * Pros: No dependencies on external libraries, easy to implement and test. * Cons: May be slower due to the absence of optimized V8 implementation. * Other consideration: This approach requires manual iteration over the array, which can lead to performance issues for large datasets. **Benchmark Results** The benchmark results show the execution rate per second (ExecutionsPerSecond) for each browser version and platform. The "normal" approach performs the worst, likely due to the lack of optimization and manual iteration. The Lodash approaches perform similarly, with `filter()` being slightly faster than `compact()`. These results can be used to compare the performance of these different approaches. **Other Alternatives** If you're looking for alternative libraries or implementations, here are a few options: * For filtering: You could use the built-in `Array.prototype.filter()` method, which is also optimized by V8. * For compacting: You could use the Array.prototype.reduce() method to remove falsey values, or implement your own logic. However, keep in mind that using external libraries like Lodash can add dependencies and potentially impact performance. In this case, since the benchmark already includes Lodash as a CDN reference, it's convenient to use its methods for comparison purposes.
Related benchmarks:
IndexOf vs Includes vs lodash includes numbers
splice vs length
splice vs length 2
Map (Lodash vs Lodash/fp vs Immutable)
Map (Lodash vs Lodash/fp vs Immutable) new versions
Comments
Confirm delete:
Do you really want to delete benchmark?