Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
loadash vs 2 filters
(version: 0)
loadash vs 2 filters
Comparing performance of:
Loadash vs 2 filters
Created:
3 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 tabl = Array.from({ length: 10000 }).map((value, i) => i)
Tests:
Loadash
const [par, impar] = _.partition(tabl, v => v % 2 === 0)
2 filters
const par = tabl.filter(v => v % 2 === 0); const impar = tabl.filter(v => v % 2 !== 0);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Loadash
2 filters
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):
**Overview** The provided JSON represents a JavaScript microbenchmark on the MeasureThat.net website, which compares the performance of two approaches: using Lodash's `partition` function and using two separate filter functions. **Benchmark Definition** The benchmark definition includes: * A script preparation code that creates an array of 10,000 numbers from 0 to 9,999. * An HTML preparation code that loads the latest version of Lodash (4.17.5) via a CDN. The benchmark itself consists of two test cases: 1. **Loadash**: The first test case uses Lodash's `partition` function to divide the array into two parts: one containing even numbers (`par`) and one containing odd numbers (`impar`). 2. **2 filters**: The second test case uses two separate filter functions to achieve the same result: filtering out even numbers and keeping only odd numbers in `par`, and filtering out odd numbers and keeping only even numbers in `impar`. **Comparison of Options** The two approaches have different pros and cons: * **Loadash's partition function**: This approach is concise and easy to read, but it may incur a slight performance overhead due to the creation of a temporary array. * **2 filters**: This approach is more explicit and easier to understand, but it requires more code and may be less efficient due to the repeated filtering operations. **Library: Lodash** Lodash is a popular JavaScript utility library that provides a wide range of functions for data manipulation, object creation, and more. In this benchmark, Lodash's `partition` function is used to divide the array into two parts based on a predicate (in this case, `v => v % 2 === 0`). This allows for a concise and expressive way to solve the problem. **Special JS Feature: None** There are no special JavaScript features or syntaxes being tested in this benchmark. The focus is solely on the performance comparison of the two approaches. **Other Alternatives** If you were to implement these tests from scratch, here are some alternative approaches: * Using `Array.prototype.reduce()` and `Array.prototype.filter()`: This approach would involve using the reduce method to iterate over the array and filter out elements based on a predicate. * Using `Array.prototype.every()` and `Array.prototype.some()`: This approach would involve using every and some methods to check if all or any elements in the array satisfy a condition. These alternatives would require more code and may not be as efficient as the original Lodash implementation.
Related benchmarks:
lodash partition vs forEach with array push vs two filter loops
lodash partition vs find and filter
lodash partition vs forEach with array spread iterator vs array push vs for each with concat vs two filters
lodash partition vs forEach with array spread iterator vs array push vs for each with concat vs two filters with 10000
Comments
Confirm delete:
Do you really want to delete benchmark?