Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Wildcard Match Test
(version: 0)
Comparing performance of:
Test True vs Test False vs Alphabet Test (many wildcards)
Created:
6 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
function matchRuleShort(str, rule) { var escapeRegex = (str) => str.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1"); return new RegExp("^" + rule.split("*").map(escapeRegex).join(".*") + "$").test(str); }
Tests:
Test True
matchRuleShort("google.com/*/search", "google.com/epic/gamer/time/search")
Test False
matchRuleShort("google.com/*/search", "google.com/epic/gamer/time/sorch")
Alphabet Test (many wildcards)
matchRuleShort("a*c*e*g*i*k*m*o*q*s*u*w*y", "abcdefghijklmnopqurstuvwxyz")
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Test True
Test False
Alphabet Test (many wildcards)
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/137.0.0.0 Safari/537.36
Browser/OS:
Chrome 137 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Test True
1861123.2 Ops/sec
Test False
1987598.2 Ops/sec
Alphabet Test (many wildcards)
3242492.8 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'll break down the provided benchmark and explain what's being tested, compared, and the pros/cons of different approaches. **Benchmark Definition** The `matchRuleShort` function is defined to test wildcard matching in regular expressions (regex). The function takes two parameters: `str` (the input string) and `rule` (the regex pattern to match). Here's a brief explanation: * The `escapeRegex` function escapes special characters in the regex pattern, ensuring it's properly escaped for use in regex. * The main function creates a new RegExp object with the escaped rule and uses it to test if the input string matches. **Options Compared** The benchmark compares three different approaches: 1. **Exact Match**: Using `^` and `$` anchors to match the entire string. 2. **Wildcard Matching**: Using `*` as a wildcard character in the regex pattern. 3. **Alphabet Test (many wildcards)**: The test case with a long sequence of lowercase letters (`abcdefghijklmnopqurstuvwxyz`) to simulate many wildcards. **Pros and Cons** 1. **Exact Match**: * Pros: Fast and efficient for exact matches, especially when using anchors. * Cons: May not be suitable for wildcard matching or when the input string doesn't match the pattern exactly. 2. **Wildcard Matching**: * Pros: Flexible and can match strings with varying lengths. * Cons: Can lead to slower performance due to the need to create a new RegExp object, which may incur additional overhead. 3. **Alphabet Test (many wildcards)**: * Pros: Simulates many wildcards, allowing for a broader test of regex engine performance. * Cons: Unconventional input string can be less representative of real-world scenarios. **Library and Special JS Features** The benchmark uses the `RegExp` object from the JavaScript Standard Library. The `matchRuleShort` function also leverages modern JavaScript features, such as arrow functions (`(str) => ...`) and template literals (`"\\$1"`). Other considerations: * **Regex Engine Optimization**: A well-optimized regex engine can significantly impact performance. Benchmarks like these help identify areas for optimization. * **Input String Length and Complexity**: The length and complexity of input strings can affect the test results, especially in cases with wildcard matching. **Alternatives** Some alternative approaches or modifications to this benchmark could include: * Using a different regex dialect (e.g., JavaScript's `RegExp` vs. .NET's `System.Text.RegularExpressions`). * Adding more complex input strings to simulate edge cases. * Comparing performance using different execution environments, such as Node.js vs. browser engines like Blink or Gecko. * Incorporating additional tests for specific use cases, like searching for multiple patterns in a single input string. Keep in mind that the goal of this benchmark is to compare different regex engine approaches and identify potential performance bottlenecks. The chosen options are intended to be representative of real-world scenarios, but further modifications can always be made to refine the test suite.
Related benchmarks:
new RegExp vs literal with groups
Regex v split/filter/join
Various regex testing patterns
Trim leading and trailing slash (regex vs split filter)
Comments
Confirm delete:
Do you really want to delete benchmark?