Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
test4534553543534543543
(version: 0)
test
Comparing performance of:
regex vs loop
Created:
7 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<article id="m32476968" class="post__message "> <a href="/po/res/32475240.html#32475240" class="post-reply-link" data-thread="32475240" data-num="32475240">>>32475240 (OP)</a><br>На что здесь триггернулся сви<sup><sup><sup><sup><sup><sup><sup><sup><sup><sup><sup><sup><sup><sup><sup><sup><sup><sup><sup><sup>о</sup></sup></sup></sup></sup></sup></sup></sup></sup></sup></sup></sup></sup></sup></sup></sup></sup></sup></sup></sup>носкрипт? </article>
Tests:
regex
var ax = document.getElementById("m32476968").innerHTML.trim(); ax = ax.replace(/(?:<su[bp]><su[bp]><su[bp]><su[bp]><su[bp]>(?!.*?<su[bp]>).*?<\/su[bp]><\/su[bp]><\/su[bp]><\/su[bp]><\/su[bp]>)+/g,""); ax = ax.replace(/<a href=.*?<\/a>|<\/?strong>|<\/?em>|(?:<\/?su[bp]>)+|<span class="[suo](?:poiler)?">|<br>/g, "");
loop
var newWord; var bx = document.getElementById("m32476968").innerHTML.trim(); bx = bx.replace(/<a href=.*?<\/a>|<\/?strong>|<\/?em>|<span class="[suo](?:poiler)?">|<br>/g, ""); while ((newWord = bx.replace(/<su[bp]><su[bp]><su[bp]><su[bp]><su[bp]>(?!.*?<su[bp]>).*?<\/su[bp]><\/su[bp]><\/su[bp]><\/su[bp]><\/su[bp]>/g, "")).length != bx.length) { bx = newWord; }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
regex
loop
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):
To explain what is tested on the provided JSON, let's break down each individual test case: **Test Case 1: "regex"** This test case measures the performance of regular expressions in JavaScript. The benchmark definition code uses `document.getElementById` to retrieve an HTML element with a specific ID, and then performs two regular expression replacements on its innerHTML: 1. The first replacement removes all occurrences of `<su[bp]>` patterns that do not follow other patterns. 2. The second replacement removes all occurrences of HTML tags (`<a>`, `<strong>`, `<em>`, `<span>`), as well as the `poiler` class, and line breaks (`<br>`). The test case measures how many times these regular expressions can be executed per second. **Pros and Cons:** * Pros: + Regular expression performance is a common aspect of JavaScript benchmarking. + Provides insight into the browser's ability to handle complex string processing. * Cons: + May not accurately represent real-world scenarios, as it only tests a specific use case. + The regular expressions used may be overly complex and not representative of typical web development tasks. **Test Case 2: "loop"** This test case measures the performance of a loop-based approach to removing HTML tags from an element's innerHTML. The benchmark definition code uses `document.getElementById` to retrieve an HTML element with a specific ID, and then performs a while loop that repeatedly replaces any remaining `<su[bp]>` patterns: 1. The replacement is done using the same regular expression as in Test Case 1. 2. The loop continues until no more replacements can be made. The test case measures how many times this loop can execute per second. **Pros and Cons:** * Pros: + Provides insight into the browser's ability to handle iterative string processing. + May be more representative of real-world scenarios, where loops are often used for text manipulation. * Cons: + The use of a while loop may introduce overhead due to condition checks. + The replacement logic is similar to Test Case 1, which may not provide distinct performance results. **Library/Features:** Neither test case uses any external libraries or special JavaScript features. They only rely on the built-in `document` and `innerHTML` APIs. **Other Considerations:** * Both tests use a single HTML element for their benchmarking, which may not accurately represent real-world scenarios where multiple elements are processed. * The use of specific IDs and classes (e.g., `poiler`) may limit the applicability of these benchmarks to other websites or content. **Alternatives:** If you were to create alternative benchmarks, you could consider: 1. Testing string concatenation performance using `+=` instead of regular expressions. 2. Measuring performance while removing HTML tags from a larger string (e.g., 1000 characters). 3. Using a different loop implementation, such as `for` or `Array.prototype.forEach()`. 4. Adding additional complexity to the replacement logic, such as supporting Unicode characters. Keep in mind that these alternatives would require significant changes to the benchmarking code and may not provide distinct performance results.
Related benchmarks:
spread vs concat 2
lodash clonedeep vs json.parse(stringify()) vs deepClone v9
class vs data-attribute
6k Test
Comments
Confirm delete:
Do you really want to delete benchmark?