HTML Preparation code:
AخA
 
1
<!--your preparation HTML code goes here-->
Script Preparation code:
 
const doc = document.createDocumentFragment()
const parser = new DOMParser
let temp
let div
let range
let html = `<div>${'<button>hii</button>'.repeat(200)}</div>`
function go(parseMode) {
    switch (parseMode) {
        case 'DOMParser':
            var element = document.adoptNode(parser.parseFromString(html, 'text/html').body.firstElementChild)
            break
        case 'write': {
            let doc = document.implementation.createHTMLDocument()
            doc.write(html)
            var element = document.adoptNode(doc.body.firstElementChild)
        }
        break
    case 'setHTMLUnsafe': {
        temp ??= document.createElement('template')
        temp.setHTMLUnsafe(html)
        var element = document.adoptNode(temp.content.firstElementChild)
    }
    break
    case 'innerHTML': {
        div ??= document.createElement('div')
        div.innerHTML = html
        var element = div.removeChild(div.firstElementChild)
    }
    break
    case 'createHTMLDocument': {
        let n = document.implementation.createHTMLDocument()
        n.body.innerHTML = html
        var element = document.adoptNode(n.body.firstElementChild)
    }
    break
    case 'createRange':
        var element = document.adoptNode((range ??= document.createRange()).createContextualFragment(html).firstElementChild)
        break
    case 'template': {
        temp ??= document.createElement('template')
        temp.innerHTML = html
        var element = document.adoptNode(temp.content.firstElementChild)
    }
    break
    case 'parseHTMLUnsafe':
        var element = document.adoptNode(Document.parseHTMLUnsafe(html).body.firstElementChild)
        break
    }
    return element
}
Tests:
  • DOMParser

     
    go('DOMParser')
  • write

     
    go('write')
  • setHTMLUnsafe

     
    go('setHTMLUnsafe')
  • innerHTML

     
    go('innerHTML')
  • createHTMLDocument

     
    go('createHTMLDocument')
  • createRange

     
    go('createRange')
  • template

     
    go('template')
  • parseHTMLUnsafe

     
    go('parseHTMLUnsafe')
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    DOMParser
    write
    setHTMLUnsafe
    innerHTML
    createHTMLDocument
    createRange
    template
    parseHTMLUnsafe

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 26 days ago)
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36 Edg/133.0.0.0
Chrome 133 on Linux
View result in a separate tab
Test name Executions per second
DOMParser 12688.2 Ops/sec
write 6134.0 Ops/sec
setHTMLUnsafe 5843.3 Ops/sec
innerHTML 13917.3 Ops/sec
createHTMLDocument 10195.1 Ops/sec
createRange 6770.5 Ops/sec
template 6101.8 Ops/sec
parseHTMLUnsafe 5748.3 Ops/sec