Test name | Executions per second |
---|---|
appendChild | 4257.5 Ops/sec |
appendChild 2 | 1876.1 Ops/sec |
appendChild 3 | 1733.5 Ops/sec |
insertAdjacentHTML | 1497.9 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 = doc.body.appendChild(doc.createElement('dialog'));
this.#dlg.id = 'dlg';
this.#dlg.className = 'fit';
this.#img = this.#dlg.appendChild(new Image());
}
#dlg;
#img;
}
const ui = new UI(document);
class UI {
constructor(doc){
this.#dlg = doc.body.appendChild(doc.createElement('dialog'));
this.#dlg.id = 'dlg';
this.#dlg.className = 'fit';
this.#img = this.#dlg.appendChild(document.createElement('img'));
}
#dlg;
#img;
}
const ui = new UI(document);
class UI {
constructor(doc){
this.#dlg = doc.body.appendChild(Object.assign(doc.createElement('dialog'),{id:'dlg',className:'fit'}));
this.#img = this.#dlg.appendChild(new Image());
}
#dlg;
#img;
}
const ui = 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;
}
const ui = new UI(document);