Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
.endsWith vs includes betterment
(version: 0)
Comparing performance of:
.endsWith vs .includes
Created:
3 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var string = 'car'; var stringToCheck = 'ICEcar'; var result = null;
Tests:
.endsWith
result = stringToCheck.endsWith(string);
.includes
result = stringToCheck.includes(string);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
.endsWith
.includes
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36
Browser/OS:
Chrome 132 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
.endsWith
7661551.0 Ops/sec
.includes
7549450.5 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the benchmark and analyze what's being tested. **Benchmark Overview** The benchmark compares the performance of two string methods: `endsWith` and `includes`. The test creates two strings, `string` and `stringToCheck`, where `stringToCheck` contains the suffix `'ICEcar'` appended to `string`. **Options Compared** The benchmark tests two options: 1. **`.endsWith()`**: This method checks if a string ends with another string. 2. **`.includes()`**: This method checks if a string contains another string. **Pros and Cons of Each Approach** * `.endsWith()`: This method is more efficient than `.includes()` because it only requires a single pass through the characters in the `stringToCheck` string, whereas `.includes()` potentially requires multiple passes. However, `.endsWith()` may not be as flexible since it can't check for prefix matches or exact matches. * `.includes()`: Pros: More flexible and forgiving than `.endsWith()`, allowing for partial matches and exact matches. Cons: Slower due to the single character scan in case of partial matches. **Library and Special JS Features** The benchmark doesn't use any external libraries. However, it does utilize special JavaScript features: * **Template Literals**: The code uses template literals (`var string = 'car';`) for string creation. * **ES6+ Methods**: Both `.endsWith()` and `.includes()` are ES6+ methods, which are supported in modern browsers. **Other Alternatives** If not using the specified options, other alternatives could include: * Using a regular expression to match the suffix or prefix (e.g., `new RegExp('Icecar$').test(string)` for `.endsWith()`) or `new RegExp('Icecar').test(string)` for `.includes()`). * Implementing custom string matching functions. Keep in mind that using regular expressions can be slower and may require more system resources than the built-in methods. Custom implementations might not be optimized for performance and could lead to inconsistent results. Overall, the benchmark provides a simple yet informative comparison between two commonly used string methods, helping users understand the relative performance of `.endsWith()` and `.includes()`.
Related benchmarks:
.endsWith vs includes
endsWith vs includes vs ===
.endsWith vs includes
.endsWith vs includes (2)
Comments
Confirm delete:
Do you really want to delete benchmark?