Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
includes vs regex testcases
(version: 0)
string.includes vs regex.test methods
Comparing performance of:
includes vs test
Created:
one year ago
by:
Guest
Jump to the latest result
Script Preparation code:
var str = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
Tests:
includes
str.includes("sdfsdkfnskdf") || str.includes("voluptate") || str.includes("elit")
test
/sdfsdkfnskdf|voluptate|elit/.test(str)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
includes
test
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36
Browser/OS:
Chrome 124 on Linux
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
includes
6958047.0 Ops/sec
test
15486632.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down what's being tested in the provided benchmark. The main goal of this benchmark is to compare the performance of two different ways to check if a string includes a specific substring: using the `string.includes()` method and using regular expressions with the `/test()` method. **`string.includes()` method:** This method checks if a given value (in this case, a substring) exists in a specified string. It returns `true` if the value is found, and `false` otherwise. Pros: * Easy to read and understand * Fast and efficient for simple cases Cons: * Can be slow for large strings or complex regular expressions * Limited functionality compared to regular expressions **Regular Expressions with `/test()` method:** This method uses a regular expression pattern to match the specified substring in the string. The `test()` method returns `true` if the pattern matches, and `false` otherwise. Pros: * Powerful for complex patterns and matching * Fast and efficient for large strings Cons: * Can be harder to read and understand due to its complexity * May require more computational resources than `string.includes()` **Library usage:** In this benchmark, the `String.prototype.includes()` method is being tested. This is a built-in JavaScript method that checks if a string includes a specified substring. **Special JS feature or syntax:** There's no special feature or syntax being specifically highlighted in this benchmark. It's focused on comparing two common string manipulation methods. Now, let's consider other alternatives for achieving similar results: * Using `string.indexOf()` instead of `includes()`: This method returns the index of the first occurrence of the substring, or `-1` if not found. * Using a library like `regex-optimizer` to optimize regular expression performance: This could potentially improve the speed of the `/test()` method. * Using a different string manipulation method, such as using `substring()` and `indexOf()`: This approach would involve splitting the string into substrings and then checking for each substring. Keep in mind that these alternatives might not be directly comparable to the benchmark's focus on `includes()` vs. regular expressions with `/test()`.
Related benchmarks:
Unnecessary non-capturing groups
RegEx.test vs. String.includes vs. String.match (long)
String.replace(RegEx) vs String.replaceAll(String)
RegEx.test vs. String.includes vs. String.match vs String.indexOf - Long String
Comments
Confirm delete:
Do you really want to delete benchmark?