Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
RegEx.test vs. String.includes vs. String.match 200
(version: 0)
Comparing performance of:
RegEx.test vs String.includes vs String.match
Created:
2 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var string = "Hello world!"; var regex = /(unsuitable|join|faint|stage|honey|selection|two|fantastic|grain|sudden|coo|hand|grateful|impinge|breath|hurt|rest|stick|safe|lewd|accessible|erratic|actually|half|tested|illumine|earn|milk|snotty|forgetful|humdrum|conquer|merge|saddle|corrupt|disillusioned|sneaky|wrathful|upset|afford|amazing|scan|watery|stormy|statement|rightful|stress|coat|scattered|classify|friend|volcano|laugh|fork|salve|contend|illuminate|bust|wild|defeated|friendly|symptomatic|historical|pleasant|greasy|brass|fling|rhetorical|sloppy|charge|flawless|outgoing|giddy|giraffe|somber|swot|aboard|fascinated|lunchroom|cherry|destruction|haircut|side|begin|cute|tin|reply|skirt|spotted|obsequious|direction|scold|scat|cemetery|foot|guess|endorse|goat|strew|tin|frog|confiscate|cave|actor|shiver|trains|uproot|spotless|system|spark|audit|home|upbeat|relation|friends|inculcate|nail|cheerful|boundless|identify|enchanting|reading|classy|caption|sash|wiggly|potato|prescribe|succinct|outrageous|beast|persuade|moldy|successful|regret|pets|daily|wonderful|fast|skillful|study|endure|hill|map|shrill|blue-eyed|endurable|cuddly|boat|K|kite|productive|white|birds|animal|transport|kid|marble|frail|giddy|truculent|opinion|decrease|cream|half|meaty|rat|mitten|unbecoming|halting|fork|scissors|smart|spin|zebra|glib|old|dedicate|voice|useful|gifted|treatment|dip|future|multiply|lead|common|bleed|like|wound|scald|grade|direful|pale|guide|evanescent|spotty|dusty|fallacious|inexpensive)/;
Tests:
RegEx.test
regex.test(string);
String.includes
string.includes("Hello");
String.match
string.match("Hello");
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):
Let's dive into the world of JavaScript microbenchmarks on MeasureThat.net. **Benchmark Definition** The provided benchmark definition is a JSON object that defines three test cases: 1. `RegEx.test`: Tests the performance of the `RegExp.test()` method. 2. `String.includes`: Tests the performance of the `includes()` method on strings. 3. `String.match`: Tests the performance of the `match()` method on strings. **Options Compared** The benchmark compares the performance of three different methods: * `RegExp.test()` * `string.includes()` * `string.match()` These methods are used to search for a specific pattern or substring within a string. The main difference between them lies in their implementation and usage: * `RegExp.test()` is a method that tests if a string matches a regular expression pattern. It returns a boolean value indicating whether the string matches the pattern. * `string.includes()` is a method that checks if a string contains a specific substring. It returns a boolean value indicating whether the substring is found in the string. * `string.match()` is a method that searches for the first occurrence of a regular expression pattern within a string and returns an array containing the match or null if no match is found. **Pros and Cons** Here's a brief overview of each option: 1. `RegExp.test()` * Pros: + Flexible: Can test for multiple patterns using the same method. + Fast: Generally faster than `string.includes()` and `string.match()` when dealing with complex patterns. * Cons: + Steeper learning curve due to regular expression syntax. + May be overkill for simple substring searches. 2. `string.includes()` * Pros: + Easy to use: Simple, intuitive syntax. + Fast: Generally faster than `RegExp.test()` and `string.match()` when dealing with short substrings. * Cons: + Limited functionality: Only checks if a specific substring is present in the string. 3. `string.match()` * Pros: + Convenient: Returns an array of matches or null, making it easy to work with multiple matches. + Fast: Generally faster than `RegExp.test()` when dealing with simple patterns. * Cons: + Less flexible: Only returns the first match (or null), limiting its use for complex searches. **Library** The benchmark uses no external libraries. However, it does rely on the built-in JavaScript methods mentioned above (`RegExp.test()`, `string.includes()`, and `string.match()`). **Special JS Feature/Syntax** None of the benchmarked methods specifically utilize special JavaScript features or syntax beyond what's commonly known. **Other Alternatives** If you're looking for alternative methods to perform string searches, consider: 1. `String.prototype.indexOf()`: Similar to `includes()`, but returns the index of the first occurrence instead of a boolean value. 2. `String.prototype.lastIndexOf()`: Returns the index of the last occurrence of a substring in a string. 3. `Array.prototype.indexOf()`: Can be used to search for an element within an array, similar to `string.includes()`. Keep in mind that these alternatives may have different performance characteristics and use cases compared to the benchmarked methods.
Related benchmarks:
RegEx.test vs. String.includes vs. String.match insensitive
RegEx.test vs. String.includes vs. String.match in case insensitive scenarios
RegEx.test vs. String.includes vs. String.match (multiple words in regex)
RegEx.test vs. String.includes vs. String.match vs String.startsWith vs String.localeCompare vs String ===
RegEx.test vs. String.includes 3
Comments
Confirm delete:
Do you really want to delete benchmark?