Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
lodash _.indexOf vs native indexOf
(version: 0)
Compare the new ES6 spread operator with the traditional concat() method
Comparing performance of:
_.indexOf vs array indexOf
Created:
5 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.11/lodash.core.js"></script>
Script Preparation code:
var users = [ { 'user': 'joey', 'age': 32 }, { 'user': 'ross', 'age': 41 }, { 'user': 'chandler', 'age': 39 } ]
Tests:
_.indexOf
_.indexOf(users, elem => elem.age < 40)
array indexOf
users.indexOf(elem => elem.age < 40)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
_.indexOf
array indexOf
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.4 Safari/605.1.15
Browser/OS:
Safari 17 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
_.indexOf
29256732.0 Ops/sec
array indexOf
598741248.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the benchmark and its options. **Benchmark Overview** The benchmark measures the performance difference between using Lodash's `_indexOf` function versus the native `indexOf` method on an array in JavaScript. **Options Being Compared** There are two main options being compared: 1. **Lodash's `_indexOf` function**: This is a utility function provided by the popular Lodash library, which is designed to provide a consistent and predictable way of finding the index of a value within an array. 2. **Native `indexOf` method on an array**: This is a built-in method in JavaScript that allows you to find the index of a value within an array. **Pros and Cons** * **Lodash's `_indexOf` function**: + Pros: Often more readable and maintainable code, especially for complex search scenarios. + Cons: May be slower than native methods due to the overhead of function calls and object lookup. * **Native `indexOf` method on an array**: + Pros: Generally faster than Lodash's `_indexOf` function because it is a built-in method that bypasses additional function call overhead. + Cons: May not provide the same level of readability or maintainability as Lodash's `_indexOf` function. **Library and Its Purpose** In this benchmark, the `lodash.js` library is used to provide the `_indexOf` function. Lodash is a popular utility belt that provides a collection of high-quality, predictable functions for common programming tasks. In this case, it's being used to provide a consistent way to find the index of a value within an array. **Special JavaScript Feature or Syntax** There doesn't appear to be any special JavaScript feature or syntax being tested in this benchmark. **Other Alternatives** If you're looking for alternative ways to achieve the same result without using Lodash, here are some options: * Using `Array.prototype.indexOf()` method directly on the array. * Using a custom implementation of `_indexOf` function that uses native methods like `Array.prototype.findIndex()`. * Using other utility libraries or frameworks that provide an implementation similar to Lodash's `_indexOf` function. Keep in mind that these alternatives may have different performance characteristics, readability, and maintainability compared to using Lodash's `_indexOf` function.
Related benchmarks:
native find vs lodash _.find
native indexOf vs lodash _.indexOf
native find vs lodash _.find_fork
lodash _.indexOf vs native indexOf with strings
Comments
Confirm delete:
Do you really want to delete benchmark?