Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
endsWith vs Regex test
(version: 0)
Comparing performance of:
Regex vs endsWith
Created:
one year ago
by:
Guest
Jump to the latest result
Tests:
Regex
/test$/.test("this is a test")
endsWith
"this is a test".endsWith("test")
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Regex
endsWith
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Mobile Safari/537.36
Browser/OS:
Chrome Mobile 124 on Android
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Regex
33582428.0 Ops/sec
endsWith
74671688.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 comparing two approaches to check if a string ends with a certain suffix: 1. Using a regular expression (`/test$/`). 2. Using the `endsWith()` method of the String object (`"this is a test".endsWith("test")`). **Options Compared** In this benchmark, we have two options being compared: * **Regex**: Using a regular expression to match the suffix at the end of the string. * **endsWith**: Using the `endsWith()` method of the String object. **Pros and Cons of Each Approach** Here are some pros and cons of each approach: * **Regex** + Pros: - Can be used to match any suffix, not just a specific one. - Can be more flexible than the `endsWith()` method. + Cons: - Can be slower than the `endsWith()` method for simple cases. - Requires additional code and complexity. * **endsWith** + Pros: - Faster and more straightforward than using a regular expression. - Only requires a single call to the `endsWith()` method. + Cons: - Limited to only checking for a specific suffix ("test" in this case). - May not be as flexible as the regex approach. **Library and Special JS Features** In this benchmark, we're using the `endsWith()` method of the String object. This is a built-in JavaScript method that was introduced in ECMAScript 2015 (ES6). No special JavaScript features or syntax are being tested in this benchmark. **Other Alternatives** Other alternatives to using regular expressions or the `endsWith()` method could include: * Using a library like Lodash's `endsWith` function. * Implementing a custom string matching algorithm. However, in this simple benchmark, the two options (regex and `endsWith`) are the most straightforward and well-supported approaches. **Benchmark Preparation Code** The script preparation code is empty, which means that no additional setup or initialization code is required before running the benchmark.
Related benchmarks:
endsWith() vs regex
endsWith vs Regex - case insensitive
endsWith vs Regex correct
endsWith vs Regex-literal
endsWith vs Regex aspx
Comments
Confirm delete:
Do you really want to delete benchmark?