Test name | Executions per second |
---|---|
appendChild | 3.8 Ops/sec |
insertAdjacentHTML | 1.6 Ops/sec |
<div><div><div></div></div></div>
<div></div>
<a href='#' />
<div></div>
<div></div>
<div><div><div></div></div></div>
<div></div>
<div><div></div></div>
<div><div></div></div>
<div><div><div><div></div></div></div></div>
<div></div>
<div></div>
for(let i of [Document,DocumentFragment,Element]){
i.prototype.$=i.prototype.querySelector;
i.prototype.$$=function(s){return[this.querySelectorAll(s)]};
}
class UI {
constructor(doc){
this.#dlg = document.createElement('dialog');
this.#dlg.id = 'dlg';
this.#dlg.className = 'fit';
this.#img = this.#dlg.appendChild(new Image());
document.body.appendChild(this.#dlg);
}
#dlg;
#img;
}
for (i = 0; i < 1000; i++) new UI(document);
class UI {
constructor(doc){
doc.body.insertAdjacentHTML('beforeend',`<dialog id="dlg" class="fit"><img></dialog>`);
this.#dlg = doc.body.$('#dlg');
this.#img = this.#dlg.$('img');
}
#dlg;
#img;
}
for (i = 0; i < 1000; i++) new UI(document);