innerHTML test

JavaScript performance comparison

Test case created by Josh

Preparation code

<div id="foo">Foo</div>
<style>
  #foo div {
    border: 1px solid red;
    padding: 1px;
  }
</style>
<script>
var nodes = Array(1000);
var root = document.getElementById('foo');
nodes[0] = root;

for (var i = 1; i < nodes.length; i++) {
  var node = document.createElement('div');
  var parent = nodes[Math.floor(Math.random() * i)];

  parent.appendChild(node);
  nodes[i] = node;
}
</script>

Preparation code output

Foo

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
innerHTML boolean
var count = 0;
if (document.getElementById('foo').innerHTML) {
  count++;
}
pending…
innerHTML string comp
var count = 0;
if (document.getElementById('foo').innerHTML != '') {
  count++;
}
pending…
nodeType check
var count = 0;
if (document.getElementById('foo').nodeType == 3) {
  count++;
}
pending…

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

Compare results of other browsers

0 comments

Add a comment