<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.core.js"></script>
const arr1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
const arr2 = arr1.filter(num => num % 2 === 0);
const arr1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
const arr2 = _.filter(arr1, num => num % 2 === 0);
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
Native JS | |
Lodash |
Test name | Executions per second |
---|---|
Native JS | 57862724.0 Ops/sec |
Lodash | 7472152.5 Ops/sec |
Benchmark Overview
MeasureThat.net is a website that allows users to create and run JavaScript microbenchmarks. The provided benchmark compares the performance of native JavaScript's filter()
method with Lodash's filter()
function.
Test Cases
There are two test cases:
filter()
method to filter an array of numbers and return only the even numbers.filter()
function to achieve the same result as Native JS.Options Compared
The two options being compared are:
filter()
methodfilter()
functionPros and Cons of Each Approach
filter()
MethodPros:
Cons:
filter()
FunctionPros:
Cons:
Library: Lodash
Lodash is a popular JavaScript utility library that provides a comprehensive set of functions for tasks such as array manipulation, string manipulation, and more. In this benchmark, Lodash's filter()
function is used to filter an array of numbers and return only the even numbers.
Special JS Feature/Syntax
There are no special JavaScript features or syntaxes being tested in this benchmark. The focus is on comparing the performance of two different approaches for filtering arrays.
Other Alternatives
If you're looking for alternative ways to implement filtering in JavaScript, some options include:
filter()
function or other third-party libraries that provide similar functionality.Keep in mind that the performance of these alternatives may vary depending on the specific use case and requirements.