createElement + insertBefore vs insertAdjacentHTML(BeforeBegin)

Benchmark created by syoichi on


Preparation HTML

<div id="test"></div>

Setup

var doc, test, parent;
    
    doc = document;
    test = doc.getElementById('test');
    
    if (!test) {
        test = doc.body.appendChild(doc.createElement('div'));
        test.id = 'test';
    }
    
    parent = test.parentNode;

Teardown


    var test;
    
    test = doc.getElementById('test');
    
    test.parentNode.innerHTML = '<div id="test"><\/div>';
  

Test runner

Ready to run.

Testing in
TestOps/sec
createElement + insertBefore
parent.insertBefore(doc.createElement('div'), test);
ready
insertAdjacentHTML(BeforeBegin)
test.insertAdjacentHTML('BeforeBegin', '<div></div>');
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.

  • Revision 1: published by syoichi on