<script src="lodash.js"></script>
var array = [Array(100000).keys()];
array.find(n => n === 99999)
_.find(array,n => n === 99999)
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
Array.prototype.find | |
Lodash find |
Test name | Executions per second |
---|---|
Array.prototype.find | 11698.5 Ops/sec |
Lodash find | 1173.5 Ops/sec |
Let's break down the benchmark and explain what's being tested.
What is being tested?
The benchmark is comparing the performance of two approaches:
Array.prototype.find
(native JavaScript method)_.find
(a method from the Lodash library)Both methods are supposed to find the first element in an array that satisfies a certain condition (in this case, n === 99999
).
Options compared
The two options being compared are:
Array.prototype.find
_.find
Pros and Cons of each approach
Array.prototype.find
)_.find
)lodash.js
), which may add overhead due to the need for loading and parsing the library.Other considerations
The benchmark is using a fixed-size array of 100,000 elements, which provides a good test case for both methods. The search condition is simple (a single number comparison), which should help to isolate performance differences between the two approaches.
Lodash library
In this benchmark, Lodash is being used as a library to provide an alternative implementation of the find
method. Lodash is a popular utility library that provides a range of functions for common tasks, such as array manipulation and data processing. In this case, the _find
method is being used to search for the first element in the array that satisfies the condition.
Special JS feature or syntax
There are no special JavaScript features or syntaxes being tested in this benchmark. The code is straightforward and uses only standard JavaScript methods and syntax.