DOM manipulation, jquery vs. native

JavaScript performance comparison

Test case created by

Preparation code

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

<div id="container" style="display:none;"></div>

      
<script>
Benchmark.prototype.setup = function() {
  function nativeDOMManipulation(iterations) {
    var i = 0,
        html = '<ul>',
        l = iterations || 0;
    for (i; i < l; i++) {
      html += '<li>List item ' + i + '</li>';
    }
    html += '</ul>';
    document.getElementById('container').innerHTML = html;
  }
  
  function jQueryDOMManipulation(iterations) {
    var i = 0,
        $li = null,
        $html = $('<ul>'),
        l = iterations || 0;
    for (i; i < l; i++) {
      $li = $('<li>');
      $li.text('List item ' + i);
      $html.add($li);
    }
    $('#container').append($html);
  }

};
</script>

Preparation code output

<div id="container" style="display:none;"></div>

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
nativeDOMManipulation(1000)
nativeDOMManipulation(1000);
pending…
jQueryDOMManipulation(1000)
jQueryDOMManipulation(1000);
pending…
nativeDOMManipulation(10000)
nativeDOMManipulation(10000);
pending…
jQueryDOMManipulation(10000);
jQueryDOMManipulation(10000);
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