Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
String: Includes vs equality check
(version: 0)
Comparing performance of:
Includes (success) vs Equality (sucess)
Created:
2 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var state = 'draft'
Tests:
Includes (success)
state.includes('draft')
Equality (sucess)
state === 'draft'
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Includes (success)
Equality (sucess)
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
5 months ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36 Edg/141.0.0.0
Browser/OS:
Chrome 141 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Includes (success)
64028204.0 Ops/sec
Equality (sucess)
63169492.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmarking scenario. **Benchmark Definition and Script Preparation Code** The provided benchmark definition is in JSON format, which defines two individual test cases for measuring performance differences between using `includes()` versus equality checks (`===`) for searching a string. The script preparation code is also included: `var state = 'draft';` This line of code sets the initial value of the variable `state` to `'draft'`. This variable will be used as the input string in both test cases. **Test Cases** There are two individual test cases: 1. **Includes (success)**: The benchmark definition for this test case is `state.includes('draft')`. This test checks whether the `includes()` method returns a boolean value (`true` or `false`) when searching for the substring `'draft'` within the `state` string. 2. **Equality (success)**: The benchmark definition for this test case is `state === 'draft'`. This test checks whether the equality operator (`===`) returns a boolean value (`true` or `false`) when comparing the `state` variable with the literal string `'draft'`. **Pros and Cons of Each Approach** * **Includes()**: This method can be more readable and maintainable, especially for larger strings. However, it may have performance implications compared to equality checks, as it has to iterate through the entire string to find the substring. + Pros: More readable, easier to use with regex patterns + Cons: May be slower due to iteration * **Equality (===)**: This approach is more straightforward and can be faster than using `includes()`, as it directly compares two values without iterating through a larger string. + Pros: Faster, simpler syntax + Cons: More verbose, may not work well with regex patterns **Library and Special JavaScript Features** In this benchmark, the `includes()` method is used, which is a standard JavaScript function. There are no other libraries or special features mentioned. **Other Alternatives** If you were to rewrite these test cases using alternative approaches, some options might include: * Using `String.prototype.indexOf()`: This would achieve similar results to `includes()`, but with a slightly different syntax. * Using regular expressions: The `includes()` method can be combined with regex patterns for more complex string searches.
Related benchmarks:
equality vs includes
Compare Or vs Includes
String equals vs String.includes
equals vs includes (one value)
Comments
Confirm delete:
Do you really want to delete benchmark?