Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
String.includes vs Regex.test
(version: 0)
Comparing performance of:
String.includes vs Regex.test
Created:
2 years ago
by:
Guest
Jump to the latest result
Tests:
String.includes
const isCeoLevel = 'this is a long string huhu (CEO_STAR) asdas '; isCeoLevel.includes("CEO_STAR");
Regex.test
const isCeoLevel = 'this is a long string huhu (CEO_STAR) asdas '; /CEO_STAR/i.test(isCeoLevel);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
String.includes
Regex.test
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 years ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36
Browser/OS:
Chrome 120 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
String.includes
1038713472.0 Ops/sec
Regex.test
51772720.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the benchmark and explain what's being tested, compared, and their pros and cons. **Benchmark Overview** The provided JSON represents two test cases that compare the performance of two string searching methods: `String.includes` and `Regex.test`. The benchmark is designed to measure which method is faster for finding a specific substring within a larger string. **Options Compared** The two options being compared are: 1. **String.includes**: This method uses the `includes()` function to search for a specified value (substring) in a given string. 2. **Regex.test**: This method uses regular expressions (regex) to search for a pattern in a string and returns a match object if found. **Pros and Cons** * **String.includes**: + Pros: Simple, efficient, and widely supported across most JavaScript engines. + Cons: May be slower than `Regex.test` for certain use cases due to its implementation details. * **Regex.test**: + Pros: More flexible and powerful than `String.includes`, especially for complex pattern matching. + Cons: Can be slower than `String.includes` for simple substring searches, as it involves more computational overhead. **Library/Functionality Used** In the provided benchmark code, the `includes()` function is used in both test cases. It's a built-in JavaScript function that checks if a string contains a specified value (substring). **Special JS Features/Syntax** There are no special JavaScript features or syntax mentioned in the provided code snippets. **Other Alternatives** For more complex pattern matching and search requirements, alternative methods could be used, such as: * Using the `RegExp` object with the `test()` method. * Utilizing libraries like Lodash or Ramda for string manipulation and searching functions. * Leveraging native browser APIs like `String.prototype.matchAll()` for more efficient string matching. **Benchmark Preparation Code** The provided JSON does not contain any script preparation code. This suggests that the benchmark is likely designed to run directly in a web environment, where the necessary JavaScript functions are already available. **Individual Test Cases** Each test case compares one specific scenario: * The first test case measures the performance of `String.includes` for finding the substring "CEO_STAR" within a longer string. * The second test case measures the performance of `Regex.test` with the same input, but using regular expressions to find the same substring. The benchmark result provided shows the execution counts per second for both test cases on a specific browser and device platform. This data can be used to determine which method performs better in this particular scenario.
Related benchmarks:
RegEx.test vs. String.includes vs. String.match insensitive
Case insensitive RegEx.test vs. String.includes when string doesn’t match
RegEx.test vs. String.includes incasesensitive
RegEx.test (with inline regex) vs. String.includes vs. String.match
regex vs includes - case insensitive
Comments
Confirm delete:
Do you really want to delete benchmark?