Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
.endsWith vs includes
(version: 0)
Comparing performance of:
endsWith() vs includes()
Created:
4 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var string = 'some string that ends with burrito'; var stringToCheck = 'burrito'; 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:
10 months ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36
Browser/OS:
Chrome 138 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
endsWith()
6358581.0 Ops/sec
includes()
11179015.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark and its test cases. **What is being tested?** The benchmark measures the performance difference between two string manipulation methods: `endsWith()` and `includes()`. These methods are used to check if a string ends with or includes a specific substring, respectively. **Options compared** There are two options being compared: 1. **`endsWith()`**: This method checks if the end of a string matches a specified value. It's used to verify that the last character of a string is equal to a given value. 2. **`includes()`**: This method checks if a string contains a specified value, without requiring the value to be at the end of the string. **Pros and Cons** * `endsWith()` + Pros: More efficient when checking if a string ends with a specific substring, as it only requires accessing a single character. + Cons: Less flexible than `includes()` and may not work correctly for strings that don't end with the specified value. * `includes()` + Pros: More flexible than `endsWith()`, as it can be used to check if any part of a string matches a specified value. However, this comes at the cost of potentially slower performance due to the need to scan the entire string. + Cons: May require more memory access and computations compared to `endsWith()`. **Library/ Framework considerations** There is no explicit library or framework mentioned in the benchmark setup. Both `endsWith()` and `includes()` are built-in methods in JavaScript, which means they don't rely on external libraries or frameworks. **Special JS features/syntax (none)** No special JavaScript features or syntax are used in this benchmark. It's a straightforward test of two basic string manipulation methods. **Other alternatives** If you wanted to write a similar benchmark, you could consider using other string manipulation methods, such as: * `indexOf()`: Similar to `includes()`, but returns the index of the first occurrence instead of a boolean value. * `lastIndexOf()`: Returns the index of the last occurrence of a specified value in a string. * Regular expressions: Can be used for more complex string matching and manipulation tasks, but may require additional setup and configuration. Keep in mind that each of these alternatives has its own trade-offs in terms of performance, flexibility, and complexity.
Related benchmarks:
.endsWith vs includes
.endsWith vs includes betterment
endsWith vs Includes
.endsWith vs includes (2)
Comments
Confirm delete:
Do you really want to delete benchmark?