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
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):
Let's break down the provided benchmark and explain what's being tested. **Benchmark Overview** MeasureThat.net is testing two different ways to display elements on a web page: using `display:block` or a plain `<br>` tag. The goal is to determine which approach is more efficient for rendering JavaScript-generated elements. **Options Compared** There are two options being compared: 1. **display:**block - This method sets the display style of an element to block, which means it will occupy the full width of its parent container and start a new line. 2. **<br>** - This method uses a plain HTML line break tag (`<br>`) to create a new line. **Pros and Cons** 1. **display:**block * Pros: can be more flexible and easier to style, as block elements have a natural width and height. * Cons: may cause layout issues if not used carefully, as it can lead to inconsistent spacing between elements. 2. **<br>** * Pros: simple and easy to use, does not affect element sizing or layout. * Cons: limited styling options, can lead to uneven spacing between elements. **Library Usage** In the provided benchmark code, the `NodeFilter` library is used in the JavaScript preparation code: ```javascript var walk = document.createTreeWalker(el, NodeFilter.SHOW_TEXT, null, false); ``` This library is a built-in part of the DOM API and provides methods for navigating and filtering elements in the Document Object Model (DOM). **Special JS Feature/Syntax** None are mentioned. **Other Considerations** 1. **Browser Support**: The benchmark assumes that the browser being tested supports the display style attribute (`display:block`) and HTML line break tags (`<br>`). 2. **Layout Engine**: The rendering engine used by the browser may affect the performance of these two options, as some engines are more efficient than others. **Alternatives** Other alternatives to compare might include: * Using inline styles (e.g., `style="display:block"`) instead of the `display` attribute. * Using CSS grid or flexbox layouts instead of block elements. * Comparing the performance of different rendering engines, such as Blink (Chrome), Gecko (Firefox), or WebKit (Safari). Please note that these alternatives may not be relevant to the specific benchmark being tested and should be considered on a case-by-case basis.
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?