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
Testing what's faster to create DOM nodes - chugging stuff inside innerHTML or parsing with DOMParser. Testing only for case of single child.
const domAsText = `<div>Hello, <b data-text="Whatever">world!</b></div>`
const getViaWrapper = (text) => {
const wrapper = document.createElement('div');
wrapper.innerHTML = text;
return wrapper.firstChild;
}
const parser = new DOMParser();
const getViaParser = (text) => {
return parser.parseFromString(text, 'text/html').body.firstChild;
}
function test(node){
if(node.querySelector('[data-text]').getAttribute('data-text') !== 'Whatever'){
throw "Fail."
}
}
Ready to run.
Test | Ops/sec | |
---|---|---|
using innerHTML |
| ready |
using DOMParser |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.