jsPerf.app is an online JavaScript performance benchmark test runner & jsperf.com mirror. It is a complete rewrite in homage to the once excellent jsperf.com now with hopefully a more modern & maintainable codebase.
jsperf.com URLs are mirrored at the same path, e.g:
https://jsperf.com/negative-modulo/2
Can be accessed at:
https://jsperf.app/negative-modulo/2
Test to see if complex tree is faster with innerHTML or native DOM, once factoring in string concat etc.
<div id="myTest"></div>
var structure = {
attributes: {
class: 'outerClass',
ID: 'outerID'
},
text: 'hello1',
children: [
{
attributes: {
class: 'innerClass',
ID: 'innerID1'
},
text: 'hello2',
}, {
attributes: {
class: 'innerClass',
ID: 'innerID2'
},
text: 'hello3',
}
]
};
function buildInnerHTML(structure) {
var aLines = [];
function createHTMLArray(node) {
aLines.push('<div ');
for (var attribute in node.attributes) {
aLines.push(attribute);
aLines.push('="');
aLines.push(node.attributes[attribute]);
aLines.push('" ');
}
aLines.push('">');
if (node.text) {
aLines.push(node.text + ' innerHTML');
}
if (node.children) {
for (var c = 0, cl = node.children.length; c < cl; c++) {
createHTMLArray(node.children[c]);
}
}
aLines.push('</div>');
}
createHTMLArray(structure);
return aLines.join('');
}
function buildDomTree(structure) {
var domTree = document.createElement('div');
if (structure.text) domTree.appendChild(document.createTextNode(structure.text + ' Native'));
for (var attribute in structure.attributes) {
domTree.setAttribute(attribute, structure.attributes[attribute]);
}
if (structure.children) {
for (var c = 0, cl = structure.children.length; c < cl; c++) {
domTree.appendChild(buildDomTree(structure.children[c]));
}
}
return domTree;
}
document.getElementById('myTest').innerHTML = '';
Ready to run.
Test | Ops/sec | |
---|---|---|
innerHTML |
| ready |
Native |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.