Reverse li

JavaScript performance comparison

Test case created by clippit

Preparation code

<ul id="for-test"></ul>
      
<script>
Benchmark.prototype.setup = function() {
  var liHtml = '';
  for (var i = 0; i < 10000; i++) {
      liHtml += '<li>' + i + '</li>'; 
  }
  document.getElementById('for-test').innerHTML = liHtml;

};

Benchmark.prototype.teardown = function() {
  document.getElementById('for-test').innerHTML = '';

};
</script>

Preparation code output

<ul id="for-test"></ul>

Test runner

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

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
appendChild
var ul = document.getElementById('for-test');
var len = 10000;
while (len--) {
    ul.appendChild(ul.childNodes[len]);
}
pending…
Array reverse
var ul = document.getElementById('for-test');
var children = Array.prototype.slice.call(ul.childNodes, 0);
var len = 10000;
var newInner = '';
children.reverse()
for (var i = 0; i < len; i++) {
    newInner += children[i].outerHTML;
}
ul.innerHTML = newInner;
pending…

Compare results of other browsers

Revisions

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

0 Comments