Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
chain of and equals vs not 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'; var exceptionArray = ["foo", "bar", "baz", "bud", "goo", "poo"]
Tests:
Array.includes
!exceptionArray.includes(stringToMatch)
Or chain
stringToMatch !== "foo" && stringToMatch !== "bar" && stringToMatch !== "baz" && stringToMatch !== "bud" && stringToMatch !== 'goo' && stringToMatch !== 'poo'
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:
2 years ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36 Edg/121.0.0.0
Browser/OS:
Chrome 121 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Array.includes
10708744.0 Ops/sec
Or chain
4022777.2 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down what's being tested in this benchmark. The main goal of this benchmark is to compare the performance of using `Array.includes` versus manually writing a chain of logical ORs to check if an element is present in an array. **What's being compared?** * Two approaches: + Using `Array.includes`, which is a built-in method for checking if an element is present in an array. + Manually writing a chain of logical ORs (`&&`) to achieve the same result. **Pros and Cons:** * **Using `Array.includes`:** + Pros: - More concise and readable code - Built-in method, so it's likely to be optimized by the JavaScript engine + Cons: - May incur overhead due to the method call and loop iteration - Might not be as efficient for very large arrays or complex checks * **Manually writing a chain of logical ORs:** + Pros: - Directly controls the execution flow, potentially leading to better performance in some cases - No overhead from method calls or loops + Cons: - More verbose and harder to read, making it less maintainable - Requires careful handling of edge cases and array sizes **Library usage:** There is no library used in this benchmark. **Special JS features or syntax:** None mentioned in the provided code. Now, let's consider alternative approaches: 1. **Using `Array.forEach` with a callback**: This could potentially be faster than using `includes`, as it avoids the overhead of method calls and loops. 2. **Using `Array.prototype.some()`**: Similar to `includes`, but uses a different implementation that might have slightly different performance characteristics. 3. **Manual loop iteration without methods**: Without using any built-in methods, you would need to iterate over the array manually using a loop, which could lead to better control over execution flow and potentially faster performance. 4. **Using SIMD instructions (if available)**: If your JavaScript engine supports SIMD instructions (e.g., Chrome 121), you might be able to use them to accelerate certain operations, but this would likely require significant changes to the code. Keep in mind that these alternatives might not be suitable for all use cases or environments, and may introduce additional complexity.
Related benchmarks:
equality vs includes
chain of or equals vs includes but smaller
chain of or equals vs includes 4
equals vs includes
Comments
Confirm delete:
Do you really want to delete benchmark?