Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Bzy INCLUDES, EXEC, MATCH Regex test
(version: 0)
Comparing performance of:
includes vs match vs exec
Created:
one year ago
by:
Guest
Go to the latest result
Tests:
includes
if (["inactive", "background"].includes("inactive")) { console.log("hello world"); }
match
if ("inactive".match(/inactive|background/)) { console.log("hello world"); }
exec
if (/inactive|background/.exec("inactive")) { console.log("hello world"); }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
includes
match
exec
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
10 months ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36 OPR/120.0.0.0 (Edition Yx 05)
Browser/OS:
Opera 120 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
includes
329K/s
match
304K/s
exec
302K/s
View exact numbers
Test name
Executions per second
✓
includes
328,620 Ops/sec
match
304,043 Ops/sec
exec
302,093 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the world of JavaScript microbenchmarks on MeasureThat.net. **What is being tested?** The provided benchmark measures the performance difference between three different approaches to test for the presence of specific strings in JavaScript: 1. `includes()`: This method checks if a string includes another string. 2. `match()` : This method searches a string for a regular expression pattern and returns an array containing information about each match (which can be null if there are no matches). 3. `exec()` : This method executes a regular expression on a string and returns the result. **Options being compared** The benchmark compares the performance of these three approaches: * **`includes()`**: Checks if a substring is present in the original string. * **`match()`**: Uses a regular expression to search for the specified pattern in the original string. If no match is found, it returns null. * **`exec()`**: Executes a regular expression on the original string and returns the result. **Pros and Cons** Here's a brief summary of each approach: * **`includes()`**: + Pros: Fast and simple to use. + Cons: Can lead to false positives if not used carefully (e.g., checking for presence of a substring that is not what you want). * **`match()`**: + Pros: Can be used with regular expressions, which provide more advanced string matching capabilities. + Cons: Can be slower than `includes()` and returns an array even if no match is found. * **`exec()`**: + Pros: Provides more control over the search process through regular expression patterns. + Cons: Can be slower than `includes()` and may not be suitable for all use cases (e.g., searching for substrings). **Library usage** None of the benchmark test cases explicitly uses a JavaScript library. However, it's worth noting that MeasureThat.net might use libraries internally to manage the benchmarking process. **Special JS features or syntax** None of the provided code snippets use any special JavaScript features or syntax beyond regular expressions. **Other alternatives** If you're looking for alternative approaches to test for string presence in JavaScript, consider: * Using a library like Lodash's `includes()` function * Implementing a custom search function using bitwise operations or other optimizations Keep in mind that the best approach depends on your specific use case and performance requirements. I hope this explanation helps software engineers understand the benchmark being tested on MeasureThat.net!
Related benchmarks
RegEx vs Include All
Case insensitive RegEx.test vs. String.includes when string doesn’t match
Comments
Confirm delete:
Do you really want to delete benchmark?