Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
match vs endsWith vs includes
(version: 0)
Comparing performance of:
match vs endsWith vs includes
Created:
4 years ago
by:
Guest
Jump to the latest result
Tests:
match
"abc".match(/abc/)
endsWith
"abc".endsWith("abc")
includes
"abc".includes("abc")
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
match
endsWith
includes
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
6 days ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/147.0.0.0 Safari/537.36 Edg/147.0.0.0
Browser/OS:
Chrome 147 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
match
15461878.0 Ops/sec
endsWith
24741896.0 Ops/sec
includes
21176680.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. **What is being tested?** The test cases compare three different string manipulation functions in JavaScript: 1. `String.prototype.match()` 2. `String.prototype.endsWith()` 3. `String.prototype.includes()` Each test case is designed to measure the performance of a specific function on a given input string: `"abc"`. **Options being compared:** * `match`: This function searches for a pattern at the beginning of a string. * `endsWith`: This function checks if a string ends with a specified suffix. * `includes`: This function checks if a string includes a specified substring. **Pros and Cons of each approach:** * `match`: + Pros: Can be used to search for patterns in strings, but can be slower than other approaches due to its algorithmic complexity. + Cons: May not be the most efficient choice for simple substring matching tasks like `endsWith` or `includes`. * `endsWith`: + Pros: Designed specifically for checking if a string ends with a certain suffix, making it potentially faster and more efficient than `match`. However, it can only search from the end of the string. + Cons: Limited to searching from the end of the string, which might not be suitable for all use cases. Can also lead to slower performance on longer strings. * `includes`: + Pros: Generally faster and more efficient than `match`, as it uses a simpler algorithm to check for substring presence. Also designed for common use cases like checking if a string contains a certain keyword or phrase. + Cons: May not be the most precise choice for specific pattern matching tasks, but suitable for general-purpose substring matching. **Library usage (if applicable):** In this benchmark, none of the test cases explicitly uses any libraries. However, it's worth noting that the `String.prototype` methods mentioned (`match`, `endsWith`, and `includes`) are part of the JavaScript language standard and do not require a library to be included in order to use them. **Special JS features or syntax:** The benchmark does not include any special JavaScript features or syntax beyond what is considered standard. However, it's essential to note that if you were to modify this test suite to include specific browser-specific features (e.g., `let`, arrow functions, or `class` declarations), the results might be affected by those differences. **Other alternatives:** If you wanted to compare these string manipulation functions with alternative approaches, you could consider using: * `String.indexOf()` instead of `match`, `endsWith`, or `includes` * Regular expressions (RegEx) for pattern matching * Custom loop-based implementations for performance comparison However, keep in mind that the current benchmark is well-suited for comparing the performance of `match`, `endsWith`, and `includes` specifically.
Related benchmarks:
endsWith() vs regex
.endsWith vs includes longer
String.includes vs. multiple String.endsWith
regex vs includes - case insensitive
Comments
Confirm delete:
Do you really want to delete benchmark?