Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
regex v regex
(version: 0)
Comparing performance of:
full regex vs small regex
Created:
6 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
string1 = "this is a long string with tagsand other things and information about life and what you would do if there were traps and mines and other things that would impose themselves on this journey if there were traps and mines and other things that would impose themselves on this journ if there were traps and mines and other things that would impose themselves on this journ if there were traps and mines and other things that would impose themselves on this journ if there were traps and mines and other things that would impose themselves on this journ if there were traps and mines and other things that would impose themselves on this journ if there were traps and mines and other things that would impose themselves on this journif there were traps and mines and other things that would impose themselves on this journ if there were traps and mines and other things that would impose themselves on this journ if there were traps and mines and other things that would impose themselves on this journ if there were traps and mines and other things that would impose themselves on this journ <br>"
Tests:
full regex
const sth = string1.replace(/<(?!br|span|html|b|a|p|i|ul|li|blockquote|hr|div|h[1-6])/g, "<");
small regex
const sth = string1.replace(/<(?!br|span)/g, "<");
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
full regex
small 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
llama3.2:3b
, generated one year ago):
I'll break down the provided JSON and explain what's being tested, compared, and the pros/cons of different approaches. **Benchmark Definition** The `benchmark definition` represents a test case that compares two approaches to processing HTML tags in a string using regular expressions (regex). The purpose of this benchmark is to measure the performance difference between these two approaches. **Script Preparation Code** The script preparation code defines a long string (`string1`) that contains various HTML tags. This string will be used as input for the test cases. **Html Preparation Code** There is no HTML preparation code provided, which means the script and benchmark definition are self-contained and do not rely on any external HTML markup. **Individual Test Cases** There are two individual test cases: 1. **"full regex"`**: This test case uses a full regex pattern to replace all HTML tags that don't match `br`, `span`, `html`, `b`, `a`, `p`, `i`, `ul`, `li`, `blockquote`, or `hr`. The goal is to prevent the browser from parsing and rendering these non-essential tags. 2. **"small regex"`**: This test case uses a smaller regex pattern that only excludes `br` and `span` tags, while still allowing other HTML tags to be processed by the browser. **Library and Purpose** The `replace()` method used in both test cases is a built-in JavaScript function that replaces occurrences of a pattern in a string with a replacement value. The purpose of this library is to provide a simple way to manipulate strings using regex patterns. **Special JS Feature/Syntax** There are no special JS features or syntax mentioned in the benchmark definition. However, it's worth noting that the `g` flag at the end of both regex patterns indicates "global" mode, which means the replacement will occur on all non-overlapping occurrences of the pattern in the string. **Pros and Cons of Different Approaches** The two test cases represent different approaches to processing HTML tags: 1. **"full regex"`**: This approach is more restrictive, as it excludes a larger number of HTML tags from being processed by the browser. However, this might lead to better performance since fewer tags need to be replaced. 2. **"small regex"`**: This approach is less restrictive and allows more HTML tags to be processed by the browser, which might result in slightly better performance but at the cost of potentially allowing non-essential tags to be rendered. **Other Alternatives** If you want to explore alternative approaches or modifications to these test cases, here are some ideas: * Use a more advanced regex pattern that excludes even more HTML tags, like `<(?!.*|br|span|/?>)`. * Use a different library or function for string manipulation, such as `String.prototype.replace()` with an optional `g` flag. * Modify the input string to include more or fewer HTML tags, which would affect the performance of both test cases. * Add additional test cases that compare other approaches, like using `DOMParser` to parse the HTML and then replacing tags.
Related benchmarks:
RegEx.test vs. String.includes vs. String.match v2
RegEx.test vs. String.includes vs. String.match vs equal operator
RegEx.test vs. String.includes vs. String.match (multiple words in regex)
RegEx.test vs. String.includes vs. String.match vs String.matchAll vs String.indexOf
RegEx.test vs. String.includes x 2
Comments
Confirm delete:
Do you really want to delete benchmark?