Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
RegEx.test vs. String.includes vs. String.match vs String.indexOf (~2000 characters)
(version: 0)
Comparing performance of:
RegEx.test vs String.includes vs String.match vs String.indexOf
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."; // ~2000 characters var regex = /tortor/;
Tests:
RegEx.test
regex.test(string);
String.includes
string.includes("tortor");
String.match
string.match("tortor");
String.indexOf
string.indexOf("tortor")
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
RegEx.test
String.includes
String.match
String.indexOf
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):
**Benchmark Overview** The provided benchmark measures the performance of three string manipulation methods in JavaScript: `regex.test()`, `string.includes()`, `string.match()`, and `string.indexOf()`. The benchmark compares these methods on a large string (~2000 characters) and reports their performance across different browsers and devices. **Tested Options** 1. **Regex Test**: This method uses a regular expression to search for a specific pattern in the string. In this case, the pattern is `"tortor"`. 2. **String Includes**: This method checks if a substring exists within the string. 3. **String Match**: This method searches for a regular expression pattern at the beginning of the string. 4. **String Index Of**: This method returns the index of the first occurrence of a specified value in the string. **Pros and Cons** 1. **Regex Test**: Pros: * Efficient for searching specific patterns. * Can be more readable than other methods for certain use cases. Cons: * May be slower for simple substring searches. 2. **String Includes**: Pros: * Fast for simple substring searches. * Easy to read and understand. Cons: * May not work correctly with edge cases or special characters. 3. **String Match**: Pros: * Efficient for searching patterns at the beginning of the string. * Can be more readable than other methods for certain use cases. Cons: * May not be suitable for finding occurrences within the string. 4. **String Index Of**: Pros: * Fast and efficient for finding indices. * Works correctly with most edge cases. Cons: * May not be as readable or intuitive as other methods. **Library Usage** None of the test cases use external libraries. **Special JS Features/Syntax** None of the benchmark definitions use special JavaScript features or syntax beyond standard ECMAScript syntax. **Other Alternatives** If these methods are not sufficient, alternative string manipulation approaches could include: 1. **String.prototype.split()**: Splits the string into an array using a separator. 2. **String.prototype.substring()**: Returns a subset of the original string. 3. **Array.prototype.indexOf()**: Finds the index of a value in an array. These alternatives may offer different performance characteristics and trade-offs depending on the specific use case.
Related benchmarks:
regex vs includes speed comparison
String Test indexOf vs Search
RegEx.test vs. String.includes vs. String.match (long)
RegEx.test vs. String.includes vs. String.match (2000 character)
Comments
Confirm delete:
Do you really want to delete benchmark?