Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
indexOf vs Lodash indexOf
(version: 0)
Comparing performance of: indexOf vs Lodash indexOf
Comparing performance of:
indexOf vs Lodash IndexOf
Created:
3 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:
data = Array.from({length: 1000}).map((e, index) => index);
Tests:
indexOf
const result = data.indexOf(999);
Lodash IndexOf
const result = _.indexOf(data, 999);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
indexOf
Lodash 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/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36
Browser/OS:
Chrome 130 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
indexOf
8084660.0 Ops/sec
Lodash IndexOf
939372.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the benchmark and analyze what's being tested. **Benchmark Definition** The benchmark compares the performance of two approaches to find an element in an array: the native `indexOf` method and the corresponding function from the Lodash library, `_.indexOf`. **Options Compared** Two options are being compared: 1. Native `indexOf` method 2. Lodash `_.indexOf` function **Pros and Cons of Each Approach** 1. **Native `indexOf` Method** * Pros: + Built-in functionality in JavaScript engines + Typically faster due to native optimization + May be more efficient for small arrays or specific use cases * Cons: + Can be slower for large arrays or complex search scenarios + May not support all array types (e.g., sparse arrays) 2. **Lodash `_.indexOf` Function** * Pros: + Convenient and readable syntax for searching arrays + Often faster than native implementation for large arrays due to internal optimizations + Supports various array types, including sparse arrays * Cons: + Requires an external library (Lodash) to be included in the test environment + May have additional overhead due to function calls and lookup **Library: Lodash** The `_.indexOf` function is part of the Lodash library, which provides a suite of functional programming utilities. In this benchmark, Lodash is used as a third-party dependency to provide an alternative implementation for the `indexOf` method. **Special JS Feature/Syntax: None** Neither test case uses any special JavaScript features or syntax that would require additional explanation. **Other Alternatives** If you wanted to compare other approaches, some alternatives could be: * Using another library or implementation (e.g., `Array.prototype.findIndex`, `findIndex` from a specific framework) * Implementing a custom search algorithm for arrays * Testing performance with different data distributions (e.g., random vs sequential numbers) Keep in mind that each alternative would require additional setup and consideration to ensure the benchmark is fair and representative of real-world scenarios.
Related benchmarks:
findIndex performance
Array.prototype.map vs Lodash.map on large data
index vs lastindexofasdf
array using indexOf vs includes vs some
Comments
Confirm delete:
Do you really want to delete benchmark?