Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
HTML Strip Regex
(version: 0)
Comparing performance of:
lazy vs character
Created:
6 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var string = new Array(10001).join('This is a string that is <mark>marked</mark>! ');
Tests:
lazy
string.replace(/<.*?>/g, '');
character
string.replace(/<[^>]+>/g, '');
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
lazy
character
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):
I'd be happy to help you understand what's being tested in this JavaScript microbenchmark. **Benchmark Overview** The benchmark is designed to compare the performance of two different regular expression (regex) replacement methods: lazy matching and character class matching. **Script Preparation Code** The script preparation code defines a string `string` with 10,001 characters, including HTML tags (`<mark>`, `<p>`, etc.) and other characters. This string is used as the input for the benchmark. **Html Preparation Code** There is no HTML preparation code provided, which means that the HTML structure of the input string is not being manipulated or parsed in this benchmark. **Test Cases** The benchmark consists of two test cases: 1. **Lazy**: This test case uses the `replace(/<.*?>/g, '')` regex pattern, which matches any character (including none) between `<` and `>`, but does not make a capture group (i.e., it's lazy). The goal is to match as few characters as possible. 2. **Character**: This test case uses the `replace(/<[^>]+>/g, '')` regex pattern, which matches any character class (`<`) followed by one or more non-`>` characters. The goal is to match all HTML tags. **Options Compared** The two test cases compare the performance of lazy matching (test case "lazy") versus character class matching (test case "character"). **Pros and Cons** * **Lazy Matching (Test Case "lazy")**: + Pros: May be faster because it doesn't have to match all possible HTML tags. + Cons: May not match all valid HTML tags, especially edge cases like `<b>`. * **Character Class Matching (Test Case "character")**: + Pros: Matches all valid HTML tags, including edge cases like `<b>`. + Cons: May be slower because it needs to match all possible characters. **Library and Purpose** There is no explicit library mentioned in the benchmark. However, the `String.prototype.replace()` method is a built-in JavaScript method that uses regular expressions under the hood. **Special JS Features/Syntax** None are explicitly mentioned. **Other Alternatives** If you were to extend this benchmark, you might consider adding additional test cases for other regex replacement methods, such as: * **Global vs. Multiline**: Test the performance of using the `g` and `m` flags with different regex patterns. * **Case Insensitivity**: Test the performance of using the `i` flag with different regex patterns. * **Capturing Groups**: Test the performance of using capturing groups (e.g., `(.*?)`) versus non-capturing groups (e.g., `(?!)`). Note that these additional test cases would require modifications to the benchmark script and HTML preparation code. Overall, this benchmark is designed to compare the performance of two different regex replacement methods in JavaScript. The results can help developers optimize their code for better performance.
Related benchmarks:
split-join vs regex replace
Regex vs split/join forks
Trim regex string
Trim regex string loop
Comments
Confirm delete:
Do you really want to delete benchmark?