HTML Preparation code:
x
 
1
2
<div id='dest'></div>
Script Preparation code:
 
const dest = document.getElementById('dest');
function escapeHtml(unsafe)
{
    return unsafe
         .replace(/&/g, "&amp;")
         .replace(/</g, "&lt;")
         .replace(/>/g, "&gt;");
 }
Tests:
  • insertAdjacentHTML+innerText

     
    for(var i=0; i<1000; ++i){
      dest.insertAdjacentHTML("beforeend", "<p></p>");
      dest.lastChild.innerText = `Hello ${i} & hello again.`;
    }
  • escape+insertAdjacentHTML

     
    var html = "";
    for(var i=0; i<1000; ++i){
      html += `<p>${escapeHtml(`Hello ${i} & hello again.`)}</p>`;
    }
    dest.innerHTML = html;
  • insertAdjacentHTML+innerText w/ lastElementChild

     
    for(var i=0; i<1000; ++i){
      dest.insertAdjacentHTML("beforeend", "<p></p>");
      dest.lastElementChild.innerText = `Hello ${i} & hello again.`;
    }
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    insertAdjacentHTML+innerText
    escape+insertAdjacentHTML
    insertAdjacentHTML+innerText w/ lastElementChild

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 2 years ago)
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:100.0) Gecko/20100101 Firefox/100.0
Firefox 100 on Windows
View result in a separate tab
Test name Executions per second
insertAdjacentHTML+innerText 259.3 Ops/sec
escape+insertAdjacentHTML 605.9 Ops/sec
insertAdjacentHTML+innerText w/ lastElementChild 239.0 Ops/sec