Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
endsWith vs includes vs ===
(version: 0)
Comparing performance of:
.endsWith vs .includes vs ===
Created:
5 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var string = 'car'; var stringToCheck = 'car'; var result = null;
Tests:
.endsWith
result = stringToCheck.endsWith(string);
.includes
result = stringToCheck.endsWith(string);
===
result = stringToCheck===string;
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
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; rv:136.0) Gecko/20100101 Firefox/136.0
Browser/OS:
Firefox 136 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
.endsWith
798909824.0 Ops/sec
.includes
760425920.0 Ops/sec
===
898561152.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark and analyze what's being tested. **What is being tested?** The provided benchmark tests three different approaches to check if a string ends with a specific suffix: `endsWith`, `.includes`, and `===` (strict equality). **Options compared:** 1. **endsWith**: This method returns `true` if the string ends with the specified suffix. 2. **.includes**: This method returns `true` if the string includes the specified suffix, regardless of its position in the string. 3. **==**: This is a strict equality operator that checks if both strings are identical, including case and whitespace. **Pros and Cons:** 1. **endsWith**: * Pros: + Fast and efficient (typically 2-3 operations) + Accurate for exact matching * Cons: + May not work correctly with non-ASCII characters or Unicode normalization + Can be slower than `.includes` if the string is very long 2. **.includes**: * Pros: + More flexible and accurate for non-exact matches (e.g., partial strings) + Faster than `endsWith` for large strings * Cons: + Slower than `endsWith` for exact matching 3. **==**: This is a strict equality operator that checks if both strings are identical, including case and whitespace. * Pros: None (it's not designed for string matching) * Cons: + Slow due to the overhead of checking for equality (typically 5-6 operations) + Inaccurate for non-ASCII characters or Unicode normalization **Library usage:** None mentioned in the provided benchmark. **Special JS feature/syntax:** No special JavaScript features or syntax are used in this benchmark. The code only uses standard JavaScript string methods and operators. **Other alternatives:** For testing string matching, other approaches could include: 1. Using regular expressions (e.g., `RegExp.test()` or `String.prototype.match()`) 2. Implementing a custom implementation using JavaScript's built-in `indexOf()` method 3. Using a library like Lodash or Ramda for optimized string matching Keep in mind that these alternatives may introduce additional complexity, overhead, or trade-offs in terms of performance and accuracy.
Related benchmarks:
.endsWith vs includes
.endsWith vs includes
.endsWith vs includes betterment
endsWith vs Includes
.endsWith vs includes (2)
Comments
Confirm delete:
Do you really want to delete benchmark?