Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
regex test1
(version: 0)
Comparing performance of:
separate regexs vs combined regex
Created:
6 years ago
by:
Guest
Jump to the latest result
Tests:
separate regexs
const envRegex = /\^[a-zA-Z0-9_]+\b/g; const dataRegex = /\$[a-zA-Z0-9_]+\b/g; const dataenvRegex = /(\$|\^)[a-zA-Z0-9_]+\b/g; const str = " background-color: #f7f7f7; opacity: [[ $pageopacity ]]; --r-nonexistentvalue: [[ $noexist ]]; --r-somevar: [[ $somevar ]]; --someevent: [[ @mousemove.clientX[#myelement] ]]; --r-mx: [[ &add(&num(^mouse_clientX), &add(101px,22), 60) ]]px; --r-my: [[ &sub(^mouse_clientY, 20) ]]px;"; str.match(envRegex); str.match(dataRegex);
combined regex
const envRegex = /\^[a-zA-Z0-9_]+\b/g; const dataRegex = /\$[a-zA-Z0-9_]+\b/g; const dataenvRegex = /(\$|\^)[a-zA-Z0-9_]+\b/g; const str = " background-color: #f7f7f7; opacity: [[ $pageopacity ]]; --r-nonexistentvalue: [[ $noexist ]]; --r-somevar: [[ $somevar ]]; --someevent: [[ @mousemove.clientX[#myelement] ]]; --r-mx: [[ &add(&num(^mouse_clientX), &add(101px,22), 60) ]]px; --r-my: [[ &sub(^mouse_clientY, 20) ]]px;"; str.match(dataenvRegex);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
separate regexs
combined regex
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
gemma2:9b
, generated one year ago):
This benchmark tests the performance of using regular expressions in JavaScript to extract specific patterns from a string. **Options Compared:** * **Separate Regexes:** This approach uses three distinct regular expressions: one for environment variables (`envRegex`), one for data variables (`dataRegex`), and another that combines both (`dataenvRegex`). Each regex is applied individually to the input string (`str`). * **Combined Regex:** A single regular expression (`dataenvRegex`) is used to capture both environment and data variable patterns within the string. **Pros/Cons:** * **Separate Regexes:** * **Pro:** Potentially more readable and maintainable if the regex patterns are significantly different. * **Con:** May be less efficient due to multiple regex executions. * **Combined Regex:** * **Pro:** More efficient as it performs a single regex execution, potentially reducing overhead. * **Con:** Can become complex and harder to read if both pattern types are very diverse. **Other Considerations:** * **Regex Complexity:** The complexity of the regex itself can significantly impact performance. Simpler regexes will generally execute faster. * **String Length:** Longer strings will take more time to process, regardless of the approach. * **Engine Optimization:** Different JavaScript engines (e.g., V8 in Chrome) have varying levels of optimization for regular expressions. **Alternatives:** * **Alternative Parsing Techniques:** Depending on the data structure and patterns, techniques like string split/replace or dedicated parsing libraries might be more efficient than regexes. * **Optimized Regex Libraries:** Specialized libraries like "regexpp" offer performance improvements over built-in JavaScript regex engines. **Note:** The benchmark results provided show that in this specific case, using a combined regex (`dataenvRegex`) is faster than using separate regexes. However, this may not always be the case and depends on various factors mentioned above.
Related benchmarks:
Various regex testing patterns
RegEx.test vs. String.includes vs. String.match vs String.search
Regex multiline whitespace tested
RegEx.test vs. String.includes vs. String.match vs String.match(regex) for starting string
Test "new RegExp(string)" vs "new RegExp(/regexp/)" vs "/regexp/"
Comments
Confirm delete:
Do you really want to delete benchmark?