Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
1000 test
(version: 0)
test the speed of finding in 1000 items
Comparing performance of:
Find vs indexOf vs includes
Created:
5 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var items = []; var i; for (i = 0; i < 1000; i++) { items.push('100' + i) }
Tests:
Find
items.find(id => id == "100995")
indexOf
items.indexOf("100995")
includes
items.includes("100995")
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Find
indexOf
includes
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into explaining the provided benchmark. **Benchmark Overview** The benchmark is designed to measure the speed of three different methods for finding an item in an array: `find`, `indexOf`, and `includes`. The test case consists of creating an array of 1000 items, each represented as a string "100" followed by a number from 0 to 999. The purpose of this benchmark is to compare the performance of these three methods in finding a specific item within the array. **Options Compared** The options compared are: 1. `find(id => id == "100995")` 2. `items.indexOf("100995")` 3. `items.includes("100995")` These three methods are all used to find the index of the item "100995" in the array. The main difference between them lies in how they handle the absence of the target element: * `find` returns `undefined` if the element is not found. * `indexOf` returns `-1` if the element is not found. * `includes` returns a boolean value (`true` or `false`) indicating whether the element is present in the array. **Pros and Cons** Here are some pros and cons of each method: * `find`: + Pros: More concise and expressive, as it uses an arrow function to define the search predicate. + Cons: May be slower than `indexOf` or `includes` due to its overhead. * `indexOf`: + Pros: Faster than `find` because it only searches for a single element, rather than iterating over the array. + Cons: Returns `-1` if the element is not found, which may not be as intuitive as returning `undefined`. * `includes`: + Pros: Returns a boolean value, making it more suitable for use in conditional statements. + Cons: May be slower than `indexOf` due to its overhead. **Library and Purpose** In this benchmark, the array is created using a simple JavaScript loop. No external libraries are required or used. **Special JS Feature or Syntax** There is no special feature or syntax being tested in this benchmark. The focus is on comparing the performance of three different methods for finding an item in an array. **Other Alternatives** Some alternative methods that could be compared in a similar benchmark include: * `binarySearch`: a more efficient algorithm for finding an element in a sorted array. * `filter` and `every`/`some`: methods that can be used to search for elements in an array, but may have different performance characteristics. Overall, this benchmark provides a good starting point for comparing the performance of different methods for finding an item in an array.
Related benchmarks:
Object key access vs array find
Object key access vs array find 100 items yeh ok
Object key access vs array find vs Set
Object key access vs array index access 1000000
Object lookup vs array lookup
Comments
Confirm delete:
Do you really want to delete benchmark?