Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
chain of or equals vs includes 4
(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.includes('banana') || stringToMatch.includes('map') || stringToMatch.includes('cloth') || stringToMatch.includes('hello') || stringToMatch.includes('person')
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
82934408.0 Ops/sec
Or chain
39361348.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark and explain what is being tested, compared, and their pros and cons. **Benchmark Overview** The benchmark measures the performance difference between using `Array.includes` and manually writing a chain of logical ORs (`||`) to check if an element exists in an array. The benchmark definition json contains two test cases: 1. **Array.includes**: This test case uses the `includes()` method on an array, passing a string as an argument. 2. **Or chain**: This test case manually writes a chain of logical ORs (`||`) to check if the same string exists in the array. **Comparison** The benchmark compares the performance of these two approaches: * **Array.includes**: The `includes()` method is used to check if an element exists in an array. * **Or chain**: A manual chain of logical ORs (`||`) is written to achieve the same result. **Pros and Cons** ### Array.includes Pros: 1. Concise and readable code 2. Easy to understand and maintain 3. Optimized for performance by the JavaScript engine Cons: 1. May have a slight overhead due to method invocation 2. Limited control over the iteration process ### Or chain Pros: 1. Provides explicit control over the iteration process 2. Can be optimized for specific use cases 3. No dependency on the `includes()` method Cons: 1. More verbose and complex code 2. May have a performance overhead due to the manual iteration 3. Less readable and maintainable compared to `Array.includes` **Library and Special JS Features** None of the test cases explicitly uses any libraries or special JavaScript features beyond the standard `Array.includes` method. **Other Alternatives** Alternative approaches could include: 1. Using `some()` method: Similar to the `Or chain` approach, but with a more concise syntax. 2. Using `every()` method: Another way to iterate over an array and check for a condition, which could potentially be optimized for performance. 3. Using bitwise operations (e.g., `>> 0`): Some older JavaScript engines might optimize bitwise operations for certain use cases. Keep in mind that these alternatives are not part of the standard JavaScript API and may have different pros and cons compared to `Array.includes`.
Related benchmarks:
chain of or equals vs includes
equality vs includes
chain of or equals vs includes but smaller
equals vs includes
Comments
Confirm delete:
Do you really want to delete benchmark?