Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Native filter VS Lodash omit. Second attempt.
(version: 1)
Comparing Native filter VS Lodash omit (2 ways)
Comparing performance of:
Native filter vs Lodash omit vs Lodash omit with function
Created:
6 years ago
by:
Registered User
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 data = []; var omitedValues = []; var dataObject = {}; var max = 1000000; var limit = max / 2; for (let i = 0; i < max; i ++) { data.push({ id: i, name: `item_${i}` }); dataObject[i] = { id: i, name: `item_${i}`}; if (i < limit) { omitedValues.push(i.toString()); } } const filter = data.filt
Tests:
Native filter
const filter = data.filter(item => { const name_index = item.name.split('_')[1]; return parseInt(name_index, 10) < limit; });
Lodash omit
const omitData = _.omit(dataObject, omitedValues);
Lodash omit with function
const omitByData = _.omit(data, (value, key) => { const name_index = value.name.split('_')[1]; return parseInt(name_index, 10) > limit; });
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Native filter
Lodash omit
Lodash omit with function
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/130.0.0.0 Safari/537.36
Browser/OS:
Chrome 130 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Native filter
10.1 Ops/sec
Lodash omit
10.3 Ops/sec
Lodash omit with function
1.1 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the benchmark and its options. **Benchmark Description** The benchmark is comparing three different approaches to filter data: Native JavaScript `filter()` method, Lodash's `omit()` function, and Lodash's `omit()` function with a custom callback function. The test case uses a simulated dataset of 1 million objects, each containing an "id" and a "name" property. **Options Compared** The three options being compared are: 1. **Native JavaScript `filter()` method**: This approach uses the built-in `filter()` method on the `data` array to filter out objects where the `name` property's second part (i.e., the part after the underscore) is greater than or equal to the `limit`. 2. **Lodash's `omit()` function**: This approach uses Lodash's `omit()` function to create a new array containing only the objects from the original dataset that are not present in the `omitedValues` array. 3. **Lodash's `omit()` function with custom callback**: This approach is similar to the previous one, but it uses a custom callback function passed to Lodash's `omit()` function to determine which objects to include or exclude. **Pros and Cons of Each Approach** 1. **Native JavaScript `filter()` method**: * Pros: Typically faster and more lightweight than using a library like Lodash. * Cons: May not be as efficient for very large datasets, and may require additional memory allocation. 2. **Lodash's `omit()` function**: * Pros: Highly optimized and efficient, especially for large datasets. * Cons: Requires the use of an external library (Lodash), which may add overhead. 3. **Lodash's `omit()` function with custom callback**: * Pros: Provides more flexibility in terms of filtering logic, but may still incur some overhead due to the use of Lodash. * Cons: May be less efficient than the native `filter()` method or the optimized `omit()` function. **Library Used** Lodash is a popular JavaScript utility library that provides a wide range of functions for tasks such as array manipulation, string manipulation, and more. In this case, the `omit()` function is used to create a new array containing only the objects from the original dataset that are not present in the `omitedValues` array. **Special JS Feature/Syntax** The benchmark uses a feature called "arrow functions" (e.g., `item => {\r\n const name_index = item.name.split('_')[1];\r\n return parseInt(name_index, 10) < limit;\r\n};`) which was introduced in ECMAScript 2015 (ES6). Arrow functions provide a concise way to define small, single-expression functions. **Alternatives** Other alternatives for filtering large datasets include: * Using the `filter()` method on an array of arrays (e.g., `data.map(item => item.filter(value => {\r\n // filter logic \r\n})))`, which can be more efficient than using the `filter()` method on a single array. * Using a library like Fast.js or Ramda, which provide optimized filtering functions for large datasets. * Implementing a custom filtering algorithm that is tailored to the specific use case and dataset.
Related benchmarks:
Filter: Lodash 2 vs Native
Filter: Lodash vs Native - same filter
Array.prototype.filter vs Lodash 4.17.5 filter
Array.prototype.filter vs Lodash filter bumped to million
Lodash.filter vs Native.filter
Comments
Confirm delete:
Do you really want to delete benchmark?