Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
chain of or equals vs includes but smaller
(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'].includes(stringToMatch)
Or chain
stringToMatch === 'banana' || stringToMatch === 'map'
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
87486008.0 Ops/sec
Or chain
186613136.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the world of JavaScript microbenchmarks! MeasuresThat.net is an online platform where users can create and run JavaScript benchmarks to compare different approaches, libraries, and optimizations. The provided benchmark definition json represents a test case that compares two approaches: using `Array.includes` versus writing a chain of logical ORs (`||`). The test case measures the performance difference between these two approaches for a specific string match condition. **What is tested?** In this benchmark, we have two test cases: 1. **Array.includes**: This approach uses the built-in `includes()` method to check if the string `'banana'` exists in an array containing two strings: `'banana'` and `'map'`. 2. **Or chain**: This approach manually writes a chain of logical ORs (`||`) to achieve the same result: ```javascript stringToMatch === 'banana' || stringToMatch === 'map' ``` **Options compared** The benchmark compares the performance of these two approaches: * **Approach 1: Array.includes** + Pros: - More concise and readable code - Built-in method with optimized implementation by the JavaScript engine - Typically faster, since it leverages the engine's optimizations + Cons: - May rely on the specific behavior of `includes()` in certain browsers or versions - Can be slower if the array is large or contains many elements * **Approach 2: Or chain** + Pros: - More control over the logic and possible customizations - No reliance on built-in methods, so results might be more consistent across browsers - Can be faster in certain edge cases (e.g., small arrays) + Cons: - Less readable and maintainable code due to the logical OR chain - May require additional optimizations or tweaks for optimal performance **Library used** In this benchmark, there is no explicit library mentioned. However, it's essential to note that the `includes()` method is a part of the JavaScript standard library. **Special JS feature or syntax** There isn't any special feature or syntax explicitly mentioned in this benchmark definition json. The code uses basic JavaScript syntax and built-in methods like `Array.includes()`. **Other alternatives** Some alternative approaches for string matching might include: * Using regular expressions (`/regex/`) * Implementing a custom string search algorithm (e.g., binary search) * Utilizing a library like Lodash or Ramda, which provide utility functions for various tasks, including string manipulation Keep in mind that the choice of approach depends on the specific use case and performance requirements. The benchmark results provided show the measured execution times for both test cases using Chrome 116 on a Mac OS X 10.15.7 environment. The `Array.includes` approach appears to be slightly faster, but the difference is relatively small.
Related benchmarks:
chain of or equals vs includes
equality vs includes
chain of or equals vs includes 4
equals vs includes
Comments
Confirm delete:
Do you really want to delete benchmark?