Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
<br> vs display:block;
(version: 0)
javascript generated Elements, when newline an Element <br> vs display:block; performance check
Comparing performance of:
<br> vs display:block;
Created:
9 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<html lang="en" dir="ltr"><head> <title>Dream in the night Lyrics - Touhou Wiki - Wikia</title> </head> <body class="mic"> <section id="WikiaPage" class="WikiaPage V2"> <p><br>The twist of time </p> </section> </body></html>
Script Preparation code:
function textNodesUnder(el){ var n, a=[], walk=document.createTreeWalker(el,NodeFilter.SHOW_TEXT,null,false); while(n=walk.nextNode()) a.push(n); return a; } function textNodeMapper(help = ['p','code',"span"]){ textNodesUnder(document.body).map(function(e){ if (!/\w/.test(e.data)){return ""} return help.map(function(lol){ if (e.parentElement.localName === lol){ return e.data} if (e.id === lol){ return e.data} if (e.parentElement.className === lol){ return e.data} return null }).toString() }).filter(Boolean) } var starterPack = ["P",'SECTION',"SPAN","CODE","DIV" ,"A","DT","DL","DD","FOOTER","MENU"] if (localStorage.getItem('name2kill') === null){ localStorage.setItem('name2kill',JSON.stringify(starterPack)); } var tableEle, trEle, thEle; tableEle = document.createElement('table'); trEle = document.createElement('tr'); thEle = document.createElement('th'); tableEle.id = "tableEle"; // tableEle.style = "display:block;"; trEle.appendChild(thEle); tableEle.appendChild(trEle); var addEle; addEle = document.createElement('button'); addEle.id = "addEle"; addEle.appendChild(document.createTextNode('add-tag,class,id-name')); //addEle.addEventListener("click", addKill); addEle.type = "button"; var removeEle; removeEle = document.createElement('button'); removeEle.id = "removeEle"; removeEle.appendChild(document.createTextNode('unlist')); //removeEle.addEventListener("click", removeKill); removeEle.type = "button"; var resetEle; resetEle = document.createElement('button'); resetEle.id = "resetEle"; resetEle.appendChild(document.createTextNode('clearlist')); //resetEle.addEventListener("click", killStorage); resetEle.type = "button"; var inputEle; inputEle = document.createElement('input'); inputEle.id = "inputEle"; inputEle.value = ''; inputEle.type = "text"; //inputEle.setAttribute('style', 'width: initial;'); var divEle; divEle = document.createElement("div"); divEle.id = "divEle"; divEle.setAttribute('style', "top: 0; right: 0; position: fixed; z-index: 2146;"); var checkExist = setInterval(function() { if (document.body) { clearInterval(checkExist); divEle.appendChild(inputEle); divEle.appendChild(addEle); divEle.appendChild(removeEle); divEle.appendChild(resetEle); // divEle.appendChild(document.createElement('br')); // tableEle.style = "display:block;"; // divEle.appendChild(tableEle); // document.body.appendChild(divEle); } }, 100);
Tests:
<br>
divEle.appendChild(document.createElement('br')); // tableEle.style = "display:block;"; divEle.appendChild(tableEle); document.body.appendChild(divEle);
display:block;
// divEle.appendChild(document.createElement('br')); tableEle.style = "display:block;"; divEle.appendChild(tableEle); document.body.appendChild(divEle);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
<br>
display:block;
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 explain the benchmark in detail. **Benchmark Definition** The provided JSON defines two test cases for measuring performance differences between using `<br>` and `display:block;` to create line breaks in HTML elements. The script preparation code creates various HTML elements, including buttons, inputs, and a table, on the page. The html preparation code includes an HTML structure with a section element. **Options Compared** The two options compared are: 1. **<br>**: Using the `<br>` tag to create line breaks in HTML elements. 2. **display:block;**: Setting the `display` property of an element to `block` using CSS. **Pros and Cons of Each Approach** 1. **<br>**: * Pros: Widespread support across browsers, simple to use. * Cons: May not be as efficient as other methods, can lead to inconsistent spacing between elements if not used carefully. 2. **display:block;**: * Pros: More flexible and powerful than `<br>`, allows for more control over layout and styling. * Cons: Requires knowledge of CSS and may not work in older browsers. **Library Usage** The benchmark uses the `document.createTreeWalker()` function, which is a part of the DOM (Document Object Model) API. This function is used to traverse the document tree and retrieve text nodes under an element. The script also uses the `localStorage` API to store a starter pack of HTML elements in case it's not available or has expired. **Special JS Features/Syntax** None mentioned in this benchmark. **Other Considerations** When creating line breaks in HTML, it's essential to consider the following: * Using `<br>` can lead to inconsistent spacing between elements if not used carefully. * Setting `display:block;` provides more control over layout and styling but requires knowledge of CSS. * The choice of method may impact page performance, especially on older devices or browsers. **Alternatives** If you need to create line breaks in HTML, consider using: 1. `<br>` with caution and careful spacing management. 2. `display:block;` with CSS for more control over layout and styling. 3. Other methods like `line-height` or `flexbox` for more flexibility and power. For measuring performance differences between these approaches, MeasureThat.net is an excellent tool that provides a controlled environment to test your code's efficiency.
Related benchmarks:
<br> vs display:block;
treewalker vs recursion
TreeWalker vs querySelectorAll (* all elements)2
Node Tree (with nextSibling) vs Direct Access
Comments
Confirm delete:
Do you really want to delete benchmark?