<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.21/lodash.min.js"></script>
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); }
arr2
.map((element) => element ** 2)
.map((element) => element -10)
.filter((element) => element % 2 === 0)
.map((element) => `result is ${element}`);
_(arr2)
.map((element) => element ** 2)
.map((element) => element -10)
.filter((element) => element % 2 === 0)
.map((element) => `result is ${element}`)
.value();
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
Native | |
Lodash.js chained wrapper |
Test name | Executions per second |
---|---|
Native | 0.3 Ops/sec |
Lodash.js chained wrapper | 0.3 Ops/sec |
Let's break down the provided benchmark and explain what's being tested.
Benchmark Definition
The benchmark compares the performance of two approaches:
map()
, filter()
, and toString()
to process an array.map()
, filter()
, and toString()
to process an array.Options Compared
The benchmark compares the performance of these two approaches for different array sizes:
max1
: 100,000 elementsmax2
: 10,000,000 elementsmax3
: 100,000,000 elementsPros and Cons
Chained Native Methods
Pros:
Cons:
Lodash.js Chained Wrapper
Pros:
Cons:
Other Considerations
The benchmark also considers the following factors:
Library: Lodash.js
Lodash.js is a popular JavaScript utility library that provides a wide range of functions for tasks such as array manipulation, string manipulation, and data transformation. In this benchmark, Lodash's map()
, filter()
, and toString()
methods are used to process an array.
Special JS Feature/Syntax
There is no specific special JavaScript feature or syntax being tested in this benchmark. The focus is on comparing the performance of two different approaches using standard JavaScript methods.
If you're interested in exploring other alternatives, some potential options include:
Keep in mind that the choice of approach will depend on the specific requirements and constraints of your project.