Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
includes vs regex
(version: 0)
Comparing performance of:
includes vs regex
Created:
2 years ago
by:
Registered User
Jump to the latest result
Script Preparation code:
var str = `Find out how to improve the speed of your web application! Create a benchmark, measure performance " of the JavaScript code and pick the fastest version. Click New benchmark to get started. Or checkout existing benchmarks that were added by the Community.`
Tests:
includes
str.includes('"') str.includes('@')
regex
/"/.test(str); /@/.test(str)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
includes
regex
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 years ago
)
User agent:
Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/113.0
Browser/OS:
Firefox 113 on Ubuntu
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
includes
20137266.0 Ops/sec
regex
10593101.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark and explain what's being tested. **Benchmark Overview** The benchmark compares the performance of two approaches to check if a substring exists in a string: 1. **`includes()` method**: A built-in JavaScript method that searches for a specified value within a string and returns `true` if it's found. 2. **Regular Expressions (`/regex`)**: A way to search for patterns in strings using special syntax. **Options Compared** The benchmark is comparing the performance of two options: 1. `includes()`: The built-in JavaScript method. 2. `/regex`: Using regular expressions to achieve the same result as the `includes()` method. **Pros and Cons** Here's a brief summary of the pros and cons of each approach: * **`includes()` Method**: + Pros: Simple, efficient, and widely supported by browsers. + Cons: May not be suitable for complex string patterns or non-ASCII characters. * `/regex`: + Pros: Flexible, powerful, and works well with complex patterns. However, it may be slower than the `includes()` method due to additional overhead. + Cons: Steeper learning curve, requires proper escaping and handling of edge cases. **Library Used (in this case)** There is no explicit library mentioned in the benchmark definition or test cases. The built-in JavaScript `includes()` method is being compared against regular expressions. **Special JS Feature/Syntax** The benchmark doesn't use any special JavaScript features or syntax that would require additional explanation. **Other Alternatives** If you're looking for alternative approaches to check if a substring exists in a string, some options include: * Using the `indexOf()` method with a negative index to search from the end of the string. * Implementing a custom algorithm using bitwise operations and looping through the string characters. * Utilizing a library like `string-parsers` or `regex-ast` for more complex patterns. However, for most use cases, the built-in `includes()` method or regular expressions will be sufficient.
Related benchmarks:
RegEx.test vs. String.includes vs. String.match vs String.indexOf v2
RegExp#test vs String#indexOf vs String#match vs pre-allocated RegExp
Comparing performance of: String.search vs String.match
Long regex test vs string includes
Comments
Confirm delete:
Do you really want to delete benchmark?