Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
equals vs includes
(version: 0)
how much of a performance deficit you can expect from using Array.includes instead of manually writing a chain of logical ORs
Comparing performance of:
Array.includes vs Or chain
Created:
2 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var stringToMatch = 'hello';
Tests:
Array.includes
['banana', 'map', 'cloth', 'hello', 'person'].includes(stringToMatch)
Or chain
stringToMatch === 'banana'
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Array.includes
Or chain
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/131.0.0.0 Safari/537.36
Browser/OS:
Chrome 131 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Array.includes
86741896.0 Ops/sec
Or chain
212867760.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark and explain what's being tested. **Benchmark Overview** The benchmark is designed to compare the performance of two approaches: using `Array.includes` and manually writing a chain of logical ORs. **Options Compared** Two options are compared: 1. **`Array.includes`**: This approach uses the built-in `includes` method on arrays to check if a specified value exists within the array. 2. **Manual OR Chain**: This approach requires manual implementation of a loop or recursive function to iterate through the array and perform a logical OR check. **Pros and Cons** Here's a brief overview of each approach: **`Array.includes`** Pros: * Concise and readable code * Built-in method is often faster and more efficient * Reduces boilerplate code Cons: * May not be as flexible or customizable as manual implementation * Can be slower for very large arrays or complex checks **Manual OR Chain** Pros: * Highly customizable and flexible * Can be optimized for specific use cases or performance requirements * No reliance on built-in methods or libraries Cons: * More verbose and error-prone code * Requires more manual maintenance and optimization **Other Considerations** When choosing between `Array.includes` and manual OR chain, consider the following factors: * **Performance**: If you need to perform complex checks or iterate over large arrays, manual implementation might be faster. For simple checks on smaller arrays, `Array.includes` is likely sufficient. * **Readability**: Choose concise and readable code when possible. Manual OR chain can become unwieldy for complex conditions. * **Maintainability**: With frequent updates to JavaScript features or libraries, consider the long-term maintainability of your implementation. **Library/Function Used** In this benchmark, no specific library is used besides the built-in `Array.includes` method. **Special JS Feature/Syntax** No special JavaScript feature or syntax is mentioned in the provided benchmark. However, keep in mind that some modern JavaScript features like async/await, let, and const might impact performance or implementation complexity. **Alternatives** If you're interested in exploring alternative approaches to this benchmark, consider: * **Regular expressions**: For string matching and comparison. * **Iterators**: For iterating over arrays or other data structures. * **Custom implementations**: Using low-level JavaScript operations (e.g., `indexOf` for array indexing). These alternatives might offer performance benefits or flexibility for specific use cases.
Related benchmarks:
equality vs includes
=== vs includes
String equals vs String.includes
equals vs includes (one value)
Comments
Confirm delete:
Do you really want to delete benchmark?