Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
.endsWith vs .includes diff strings
(version: 0)
Comparing performance of:
.endsWith vs .includes
Created:
2 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var stringEnd = '.svg'; var stringInclude = 'v2assets' var stringToCheck = 'http://localhost:4200/v2assets/images/icon-svgs/icon-close.component.svg'; var result = null;
Tests:
.endsWith
result = stringToCheck.endsWith(stringEnd);
.includes
result = stringToCheck.includes(stringInclude);
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:
2 years ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36
Browser/OS:
Chrome 121 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
.endsWith
9373343.0 Ops/sec
.includes
8799736.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down what's being tested in this benchmark. **What is being tested?** The benchmark measures the performance difference between two string methods: `endsWith` and `.includes`. The test case uses predefined strings: * `stringEnd`: ends with ".svg" * `stringInclude`: contains "v2assets" * `stringToCheck`: a specific URL that ends with ".svg" **Options being compared** The benchmark compares the performance of two options: 1. **`endsWith(stringEnd)`**: checks if `stringToCheck` ends with `stringEnd`. 2. **`.includes(stringInclude)`**: searches for `stringInclude` within `stringToCheck`. **Pros and Cons:** * `.endsWith(stringEnd)`: advantages: + More explicit and efficient way to check if a string ends with a specific substring. + Can be faster in some cases, as it only checks the end of the string. * `.includes(stringInclude)` : disadvantages: + May be slower due to the overhead of searching for a substring within the entire string. + Requires more memory allocations and comparisons. **Other considerations:** * The benchmark uses a URL `stringToCheck` that is quite long, which may affect performance. In a real-world scenario, strings might be shorter or more variable, impacting the results. * The test doesn't account for edge cases like an empty string, null, or undefined inputs. **Library and purpose:** There are no external libraries mentioned in this benchmark. **Special JavaScript feature or syntax:** None mentioned in this specific benchmark. However, if you were to analyze other benchmarks on MeasureThat.net, you might find examples of more advanced features like async/await, Web Workers, or specific browser-specific APIs. **Alternative approaches:** Other alternatives for string manipulation might include: * Using regular expressions (` RegExp.test()` ) for substring searching. * Employing a custom implementation using bitwise operations and indexing (e.g., `stringToCheck.charCodeAt(stringToCheck.length - 1) == stringEnd.charCodeAt(stringEnd.length - 1)`). * Leveraging native string methods like `indexOf()` or `lastIndexOf()` in combination with comparisons. Keep in mind that the choice of approach depends on the specific use case, performance requirements, and potential trade-offs.
Related benchmarks:
.endsWith vs includes
.endsWith vs includes
.endsWith vs includes with result being at the end
.endsWith vs includes (2)
Comments
Confirm delete:
Do you really want to delete benchmark?