Dynamic jQuery element rendering

JavaScript performance comparison

Test case created

Info

Tests the performance of calling jQuery.append() n times vs the performance of pushing n elements to an array and calling jQuery.html(arr.join('')).

Preparation code

<div id="main"></div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script>
Benchmark.prototype.setup = function() {
    var element = $('#main');
};

Benchmark.prototype.teardown = function() {
    $('#main').empty();
};
</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
n - appends
var i, len;

for(i = 0, len = 1000; i < len; i = i + 1) {
  element.append('<div class="child"></div>');
}
pending…
n - pushs
var arr = [];

for(i = 0, len = 1000; i < len; i = i + 1) {
  arr.push('<div class="child"></div>');
}

element.html(arr.join(''));
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