Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
RegEx.test vs. String.includes vs. String.match (2000 character)
(version: 0)
Comparing performance of:
RegEx.test vs String.includes vs String.match
Created:
3 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var string = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin eget tincidunt lacus, eget suscipit massa. Pellentesque tempor rutrum semper. Vestibulum eget lacus commodo, luctus libero quis, commodo sapien. Sed sagittis eu velit vitae dapibus. Donec viverra, sapien ac porta aliquet, risus est aliquet lectus, vitae maximus mauris diam vitae mi. Morbi in arcu lorem. Maecenas accumsan finibus varius. Nullam pellentesque id sem eu molestie. Sed ut urna risus. Donec venenatis at tellus vel posuere. Mauris vitae malesuada neque. Nullam bibendum maximus nisi. Praesent finibus porta risus, a rhoncus massa ultrices a. Aenean gravida justo at arcu sodales consectetur. Maecenas lobortis commodo nunc, sed tempor massa finibus non. Pellentesque a ante a lorem convallis commodo. Suspendisse potenti. Maecenas blandit eu arcu eget bibendum. Curabitur cursus quam eleifend fermentum molestie. Sed lacinia aliquam eleifend. Phasellus vel placerat velit, eu posuere tortor. Aenean varius mauris ut luctus faucibus. Nullam ut lacus in erat imperdiet venenatis. Duis suscipit nibh nec tristique tempus. Suspendisse nec lacus lacus. Pellentesque finibus pellentesque purus. Sed erat lorem, mollis ac metus a, volutpat facilisis lorem. Etiam venenatis commodo purus, vel dignissim felis sodales id. Curabitur ac volutpat nisi. Mauris ultricies odio nec enim tincidunt consequat non nec libero. Vestibulum faucibus elementum gravida. Curabitur vitae nibh quis leo gravida varius ut ac magna. Sed posuere feugiat dignissim. Integer nec auctor purus. Vestibulum ipsum neque, volutpat id nisl auctor, dictum interdum mi. Suspendisse commodo eros id pellentesque iaculis. Proin luctus purus elit, sit amet lobortis dolor lacinia vitae. Nullam lobortis sit amet nunc quis bibendum. Praesent ac nisl id lectus fermentum porta ut eget erat. Nullam vel ligula congue lectus faucibus gravida. Praesent condimentum semper orci, vitae maximus neque bibendum sit amet. Fusce pellentesque at felis eu sodales. Suspendisse augue."; var regex = /tortor/;
Tests:
RegEx.test
regex.test(string);
String.includes
string.includes("tortor");
String.match
string.match("tortor");
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
RegEx.test
String.includes
String.match
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'll break down the provided JSON and explain what's being tested, compared, and their pros and cons. **Benchmark Definition** The benchmark is designed to compare three different approaches for searching a string: 1. `RegEx.test()`: A regular expression method to test if a string contains a specified pattern. 2. `string.includes()`: A built-in JavaScript method to check if a string includes another string or substring. 3. `string.match()`: Another regular expression method to find the first match of a pattern in a string. **Script Preparation Code** The script preparation code defines: * A 2000-character string `string` containing some text with the word "tortor" multiple times. * A regular expression object `regex` that matches only the word "tortor". **Html Preparation Code** There is no HTML preparation code provided, so this step can be skipped. **Individual Test Cases** The benchmark consists of three individual test cases: 1. `RegEx.test()`: This test case runs the `RegEx.test()` method on the prepared string with the `regex` object. 2. `String.includes()`: This test case runs the `includes()` method on the prepared string with the substring "tortor". 3. `String.match()`: This test case runs the `match()` method on the prepared string with the regular expression `regex`. **Comparison** The benchmark compares the execution time of each test case across different browsers and devices: * The raw UA string, browser version, device platform, operating system, executions per second (FPS), and test name are provided for each test case. **Pros and Cons** Here's a brief analysis of the pros and cons for each approach: 1. `RegEx.test()`: * Pros: Can be more flexible than `includes()` or `match()` when dealing with complex patterns. * Cons: Regular expression syntax can be error-prone, slow, and resource-intensive compared to built-in methods. 2. `string.includes()`: * Pros: Fast, lightweight, and easy to use for simple substring searches. * Cons: Can be slower than regular expressions for more complex searches or when using Unicode characters. 3. `string.match()`: * Pros: Similar to `includes()`, but can capture multiple matches if needed. * Cons: Slower than `RegEx.test()` and may be less flexible. **Other Considerations** When choosing between these approaches, consider the following factors: * Complexity of the search pattern * Performance requirements (e.g., real-time or high-throughput applications) * Character encoding and Unicode support **Alternatives** Some alternative methods for string searching could include: 1. `RegExp.prototype.test()`: Similar to `RegEx.test()`, but with more flexibility in regular expression syntax. 2. `String.prototype.startsWith()`/`String.prototype.endsWith()`: For prefix or suffix matching, respectively. 3. Regular expressions with character classes (e.g., `\w+`) for simple word searches. Keep in mind that the best approach will depend on the specific requirements of your use case and performance constraints.
Related benchmarks:
RegEx.test vs. String.includes vs. String.match (case insensitive)
indexOf vs regex vs RegExp regexp fork 3
RegEx.test vs. String.includes vs. String.match vs String.startsWith vs String.localeCompare vs String ===
Case insensitive search: regex.test() vs string.toLowerCase().includes()
IndexOf vs Includes in string - larger string edition
Comments
Confirm delete:
Do you really want to delete benchmark?