DOM manipulation, jquery vs. native

JavaScript performance comparison

Test case created

Preparation code

<script src="//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

Test runner

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

Java applet disabled.

Testing in unknown unknown
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

Add a comment