Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
endsWith vs Regex - case insensitive
(version: 0)
Comparing performance of:
Regex vs endsWith
Created:
4 years ago
by:
Guest
Jump to the latest result
Tests:
Regex
/test$/gi.test("this is a teST")
endsWith
"this is a teST".toLowerCase().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 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36 Edg/131.0.0.0
Browser/OS:
Chrome 131 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Regex
5493521.0 Ops/sec
endsWith
9122139.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'd be happy to help you understand the benchmark being tested on MeasureThat.net. **What is being tested?** The provided JSON represents a benchmark that tests two approaches for checking if a string ends with a specific substring: the `endsWith` method and a regular expression (`/test$/gi.test("this is a teST")`). The goal of this benchmark is to determine which approach is faster on average. **Options compared** Two options are being compared: 1. **endsWith**: This method uses the JavaScript string function `endsWith()` that checks if a string ends with another substring. 2. **Regular expression (`/test$/gi.test("this is a teST")`)**: This approach uses a regular expression to check if the input string ends with the specified substring. The `/test$/` pattern matches any character (except newline) at the end of the string, and the `g` flag performs a global match, while the `i` flag makes the match case-insensitive. **Pros and Cons** Here's a brief summary of the pros and cons of each approach: 1. **endsWith** * Pros: + More intuitive and readable code + Generally faster than regular expressions for simple string matching * Cons: + May not be as flexible as regular expressions (e.g., it only checks for exact matches) 2. **Regular expression (`/test$/gi.test("this is a teST")`)** * Pros: + Highly flexible and can match patterns that `endsWith()` may not + Can perform case-insensitive matching (thanks to the `i` flag) * Cons: + Can be slower than `endsWith()` for simple string matching due to the overhead of compiling a regular expression **Other considerations** When choosing between these two approaches, consider the following: * For most use cases, `endsWith()` is sufficient and provides better performance. * If you need more complex pattern matching or want to ensure case-insensitivity, regular expressions might be a better choice. **Library and syntax** In this benchmark, no libraries are explicitly mentioned. However, the `endsWith` method is part of the JavaScript standard library. There are no special JavaScript features or syntax being used in this benchmark other than regular expression syntax (`/test$/gi.test("this is a teST")`).
Related benchmarks:
endsWith vs Regex correct
Case insensitive RegEx.test vs. String.includes when string doesn’t match
Case Insensitive RegEx.test vs. String.includes
regex vs includes - case insensitive
Comments
Confirm delete:
Do you really want to delete benchmark?