Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash.js vs Native - filter
(version: 0)
Comparing performance of:
Native vs Lodash.js filter
Created:
one year ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.4/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 arr1 = []; //for (var i = 0; i <= max1; i++) { arr1.push(i); } var arr2 = []; for (var i = 0; i <= max2; i++) { arr2.push(i); } var arr3 = []; //for (var i = 0; i <= max3; i++) { arr3.push(i); }
Tests:
Native
arr3.filter(el => el % 10);
Lodash.js filter
_.filter(arr3, (el) => el % 10);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Native
Lodash.js filter
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36
Browser/OS:
Chrome 127 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Native
6784802.0 Ops/sec
Lodash.js filter
2542278.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark test cases and explain what is being tested, compared, and their pros and cons. **Benchmark Definition Json** The benchmark is comparing two approaches to filter an array: 1. Native JavaScript filtering 2. Lodash.js filtering (using the `filter` function from the Lodash library) **Script Preparation Code** The script preparation code generates three large arrays (`arr1`, `arr2`, and `arr3`) with a maximum of 100,000, 10,000,000, and 100,000,000 elements, respectively. These arrays are used as input for the filtering operations. **Html Preparation Code** The HTML preparation code includes a script tag that loads the Lodash library version 4.17.4 from a CDN. **Individual Test Cases** There are two test cases: 1. **Native**: This test case uses native JavaScript's `filter` function to filter out elements in `arr3` where the remainder of the element when divided by 10 is not zero. 2. **Lodash.js filter**: This test case uses Lodash's `filter` function from the loaded library to achieve the same filtering operation as the Native test case. **Comparison** The comparison between Native and Lodash.js filtering involves measuring the performance (number of executions per second) of each approach on the generated large arrays. **Pros and Cons** **Native JavaScript Filtering:** Pros: * No additional library overhead * Performance is generally better since it's a built-in function * May be more efficient for small to medium-sized inputs Cons: * Can be slower for very large inputs due to overhead from garbage collection or other factors * May not be as readable or maintainable, especially for complex filtering operations **Lodash.js Filtering:** Pros: * Provides a concise and expressive way to perform filtering operations * Often includes additional utility functions that can simplify code * Can provide better performance for very large inputs due to optimized internal implementations Cons: * Adds an additional library dependency (Lodash) * May introduce overhead due to the need to load and initialize the library * Can make code more verbose, especially if not used judiciously **Library: Lodash** Lodash is a popular JavaScript utility library that provides a collection of functions for common programming tasks, including array manipulation, string processing, and functional programming. In this benchmark, Lodash's `filter` function is used to filter the elements in `arr3`. **Special JS Features or Syntax** None are explicitly mentioned in the provided code snippets. **Alternatives** Other alternatives to native JavaScript filtering include: * Using other libraries like Ramda.js or Immutable.js * Implementing custom filtering functions using higher-order functions (e.g., map, reduce) * Using other programming languages that provide built-in filtering support (if applicable) Keep in mind that the choice of approach depends on the specific requirements and constraints of your project.
Related benchmarks:
Lodash.js vs Native isArrary
Lodash.js vs Native _.min
Lodash.js vs Native (filter)
Lodash.js wrapper vs js native
Comments
Confirm delete:
Do you really want to delete benchmark?