<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script>
var array = [
{ 'name': 'lim', 'age': 26 },
{ 'name': 'kim', 'age': 28 },
{ 'name': 'choi', 'age': 32 },
{ 'name': 'park', 'age': 21 }
];
_.find(array, arr => arr.age < 28)
array.find(arr => arr.age < 28)
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
lodash find method | |
es6 find method |
Test name | Executions per second |
---|---|
lodash find method | 27075572.0 Ops/sec |
es6 find method | 131598512.0 Ops/sec |
I'd be happy to explain what's being tested on the provided JSON.
Benchmark Overview
The benchmark is comparing two JavaScript methods: _.find
from the Lodash library and the built-in find
method in ES6 (ECMAScript 2015). The goal is to determine which method is faster when searching for a specific element in an array based on a given condition.
Options Compared
There are two options being compared:
Pros and Cons
Lodash's _.find:
Pros:
Cons:
ES6's Array.prototype.find:
Pros:
Cons:
Library: Lodash
Lodash is a popular JavaScript utility library that provides a wide range of functions for tasks like array manipulation, object processing, and more. The _
symbol is used to access its functions.
In this benchmark, Lodash's _.find
function is used to find the first element in the array
that satisfies the condition arr => arr.age < 28
.
Special JS Feature/Syntax: None
There are no special JavaScript features or syntax used in this benchmark. The code is written in standard ES6 syntax.
Other Alternatives
If you're interested in alternatives to Lodash, some popular options include:
For built-in ES6 methods, you can use the following alternatives:
Array.prototype.find
, but returns -1 if no element is found