Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
.endsWith vs includes with result being at the end
(version: 0)
Comparing performance of:
.endsWith vs .includes
Created:
one year ago
by:
Guest
Jump to the latest result
Script Preparation code:
var string = '"assets/images/add-record-anger-menu-icon-duplicate.svg?v=ANGER_MANAGEMENT_ACTIONS"'; var stringToCheck = 'ANGER_MANAGEMENT_ACTIONS'; 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/124.0.0.0 Safari/537.36
Browser/OS:
Chrome 124 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
.endsWith
5281318.5 Ops/sec
.includes
5933439.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the benchmark and explain what's being tested. **Benchmark Definition** The benchmark is designed to compare two string manipulation methods in JavaScript: `endsWith` and `includes`. The goal is to measure which method is faster for this specific use case. **Script Preparation Code** The script prepares a variable `string` with a URL-like value, and another variable `stringToCheck` with the value "ANGER_MANAGEMENT_ACTIONS". These variables will be used in the test cases. **Test Cases** There are two test cases: 1. `.endsWith` 2. `.includes` Each test case uses the same `stringToCheck` and `string` variables. The only difference is the method being tested: `endsWith` or `includes`. **What's being compared?** The benchmark compares the execution time of each method for a specific use case: * Checking if a string ends with another string (`string.endsWith(stringToCheck)`). **Options Compared** In this benchmark, we have two options being compared: 1. **`.endsWith()`**: This method checks if the end of the string matches the given value. 2. **`.includes()`**: This method checks if the string contains the given value. **Pros and Cons of each approach:** * `.endsWith()`: This method is more efficient for certain use cases, as it only needs to traverse a subset of characters in the string to check if they match. However, it may be slower than `.includes()` for longer strings or when checking for substrings. * `.includes()`: This method is generally faster and more versatile, as it can find any substring within the original string, not just the end. However, it may be less efficient for exact matching checks like `endsWith`. **Other Considerations:** * Regular expressions (regex) could also be used to implement these methods, but that's not what's being compared in this benchmark. * The benchmark doesn't consider the impact of the string length on performance. For very long strings, `.includes()` might still be faster due to its ability to find substrings. **Library Usage** There is no library explicitly mentioned in the code or benchmark definition. However, JavaScript engines like V8 (used by Chrome) and SpiderMonkey (used by Firefox) implement these methods as part of their internal string manipulation logic. **Special JS Feature or Syntax** This benchmark doesn't use any special JavaScript features or syntax that's not widely supported across different browsers and versions. The code is simple and straightforward, making it easy to understand and compare the performance of each method.
Related benchmarks:
.endsWith vs includes
.endsWith vs includes betterment
.endsWith vs .includes diff strings
.endsWith vs includes (2)
Comments
Confirm delete:
Do you really want to delete benchmark?