<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.4/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); }
for (let i = 0; i < 10000; ++i)
console.log(arr2.length)
for (let i = 0; i < 10000; ++i)
console.log(_.size(arr2))
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
Native | |
Lodash |
Test name | Executions per second |
---|---|
Native | 4.1 Ops/sec |
Lodash | 4.3 Ops/sec |
Let's break down the provided benchmark and its options.
Benchmark Definition
The test case measures the performance of two approaches: native JavaScript and Lodash (a popular utility library for JavaScript).
Script Preparation Code
The script preparation code initializes three arrays:
arr1
: An empty array filled with values from 0 to max1
(100,000).arr2
: Another empty array filled with values from 0 to max2
(10,000,000).arr3
: A third empty array filled with values from 0 to max3
(100,000,000).The script preparation code is identical for both approaches.
Html Preparation Code
The HTML preparation code includes a reference to the Lodash library, version 4.17.4, using a CDN link.
Options Compared
The benchmark compares two options:
Pros and Cons of Different Approaches
Library: Lodash
Lodash is a popular utility library for JavaScript that provides various functions for common tasks, such as:
size
, each
)In this benchmark, Lodash is used to measure the performance of the _.size
function on an array.
Special JS Feature or Syntax
There are no special JavaScript features or syntax mentioned in the provided code. The focus is on comparing two approaches: native JavaScript and Lodash.
Other Alternatives
If you wanted to add more alternatives, you could consider using other libraries like:
Keep in mind that each alternative would introduce additional dependencies and potentially affect the benchmark's accuracy.
I hope this explanation helps!