Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
lodash vs es6 in indexOf method
(version: 0)
Comparing performance of:
lodash indexOf method vs es6 indexOf method
Created:
6 years ago
by:
Registered User
Jump to the latest result
HTML Preparation code:
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script>
Script Preparation code:
var array = ['a', 'b', 'c', 'd', 'e', 'f', 'g'];
Tests:
lodash indexOf method
var result = _.indexOf(array, 'd') > -1;
es6 indexOf method
var result = array.indexOf('d') > -1;
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
lodash indexOf method
es6 indexOf method
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 years ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36
Browser/OS:
Chrome 121 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
lodash indexOf method
11002959.0 Ops/sec
es6 indexOf method
26855886.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the world of MeasureThat.net and explore what's being tested in this benchmark. **What is being tested?** The provided JSON represents a JavaScript microbenchmark that compares two approaches to finding an element in an array: Lodash's `indexOf` method and the native ES6 `indexOf` method. **Options compared:** There are two main options being compared: 1. **Lodash's `indexOf` method**: This is a utility function provided by the popular JavaScript library Lodash. It returns the index of the first element in the array that matches the specified value, or -1 if no match is found. 2. **Native ES6 `indexOf` method**: This is a built-in method of the Array prototype in modern JavaScript, introduced in ECMAScript 2015 (ES6). It does essentially the same thing as Lodash's `indexOf`, but it's implemented in native code, which can lead to better performance. **Pros and cons:** * **Lodash's `indexOf` method**: Pros: + Well-maintained and widely used library. + Can be useful if you need a simple way to find an element in an array without worrying about the details of the implementation. Cons: + Adds overhead due to the function call and the need to load the Lodash library. * **Native ES6 `indexOf` method**: Pros: + Faster, since it's implemented in native code. + More efficient, as it avoids the overhead of a function call. However, there are some potential downsides: * The native implementation might not be optimized for all use cases or edge scenarios. * If you're using an older JavaScript engine that doesn't support ES6 features, this method won't work. **Library and its purpose:** In this benchmark, Lodash is a popular JavaScript library that provides a collection of useful functions for tasks such as array manipulation, string manipulation, and more. In this specific case, the `indexOf` method is used to find an element in an array. **Special JS feature or syntax:** There are no special JS features or syntaxes being tested in this benchmark. The code simply uses standard JavaScript features like arrays and the `indexOf` method. **Other alternatives:** If you're looking for alternative ways to find an element in an array, here are a few options: 1. **Array.prototype.findIndex()**: Introduced in ES6, this method returns the index of the first element that satisfies the provided condition. 2. **Array.prototype.forEach()**: While not specifically designed to find an element, `forEach()` can be used with a callback function that checks for the presence of the desired value. Keep in mind that these alternatives might have different performance characteristics compared to Lodash's `indexOf` method or the native ES6 `indexOf` method. Overall, this benchmark provides a simple and straightforward way to compare the performance of two approaches to finding an element in an array.
Related benchmarks:
findIndex performance
lodash vs es6 in includes method
lodash _.indexOf vs native indexOf with strings
my test lodash vs native
Comments
Confirm delete:
Do you really want to delete benchmark?