Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
match vs includes vs endsWith
(version: 0)
Comparing performance of:
match vs includes vs endsWith
Created:
one year ago
by:
Registered User
Jump to the latest result
Script Preparation code:
var names = [ ".b-island-header-content-is-style-loaded", ".b-island-header-content_island_top", ".b-island-header-content_island_bottom", ".b-island-header-content_island_all-sides", ".b-island-header-content__wrapper", ".b-island-header-content_display-bottom-island-padding_false .b-island-header-content__bottom-island", ".b-island-header-content__bottom-island" ];
Tests:
match
names.forEach((name) => { var matches = name.match(/^\.([\w-]+)-is-style-loaded$/); if (matches != null) { console.log(matches[1]); } });
includes
names.forEach((name) => { if (name.includes('-is-style-loaded')) { console.log(name.slice(0, name.length - '-is-style-loaded'.length)) } });
endsWith
names.forEach((name) => { if (name.endsWith('-is-style-loaded')) { console.log(name.slice(0, name.length - '-is-style-loaded'.length)) } });
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
match
includes
endsWith
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 YaBrowser/24.7.0.0 Safari/537.36
Browser/OS:
Yandex Browser 24 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
match
224476.8 Ops/sec
includes
267484.2 Ops/sec
endsWith
287703.5 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the world of JavaScript microbenchmarks on MeasureThat.net. **Benchmark Definition** The benchmark definition is a JSON object that provides context for the test cases. In this case, it's not explicitly stated what the test cases are measuring, but based on the script preparation code and individual test cases, we can infer that the benchmarks are comparing the performance of three string matching algorithms: 1. `match()` (also known as regular expression matching) 2. `includes()` 3. `endsWith()` These algorithms are used to search for patterns within strings. **Options Compared** The options being compared in this benchmark are: * `match()`: uses a regular expression to match the string * `includes()`: searches for the specified pattern within the string, but doesn't require it to be a whole word * `endsWith()`: checks if the string ends with the specified suffix **Pros and Cons** Here's a brief overview of each approach: * **match()**: Pros: + Can be more expressive than other methods (e.g., can capture groups) + Supports regular expressions, which can be powerful for complex patterns * Cons: + Can be slower due to the overhead of compiling and executing regular expressions + May have performance issues with very large or complex strings * **includes()**: Pros: + Faster than `match()` because it doesn't require compiling a regular expression + Simplifies many use cases where only a substring is needed * Cons: + Can be less expressive than `match()` due to limitations on the pattern syntax + May return false positives if the pattern is not unique * **endsWith()**: Pros: + Fast because it uses a simple prefix check + Suitable for use cases where only the ending part of the string needs to match * Cons: + Limited to matching only at the end of the string + May return false positives if the pattern is not unique **Library Usage** None of the provided benchmark test cases explicitly mention a library being used. However, it's worth noting that some of these functions (e.g., `match()`, `includes()`) are built-in to JavaScript and don't require any external libraries. **Special JS Features or Syntax** There isn't any specific JavaScript feature or syntax mentioned in the benchmark definitions. **Other Considerations** When choosing between these string matching algorithms, consider the following: * Use `match()` when you need a more flexible and expressive pattern. * Choose `includes()` for simple substring matches where performance is crucial. * Opt for `endsWith()` when only the ending part of the string needs to match. For alternative approaches, other JavaScript methods can be used to achieve similar results. Some examples include: * Using `String.prototype.indexOf()` or `String.prototype.lastIndexOf()` for substring matching * Implementing custom prefix checks using bitwise operations (e.g., checking if a byte matches a specific value) * Using regular expression engines like RegExp (which is the same as match())
Related benchmarks:
.endsWith vs includes
match vs endsWith vs includes
.endsWith vs includes
Compare Or vs Includes
.endsWith vs includes (2)
Comments
Confirm delete:
Do you really want to delete benchmark?