Table Creation

JavaScript performance comparison

Test case created

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<table id="table">
  <tbody id="mybody">
  </tbody>
</table>
<script>
Benchmark.prototype.teardown = function() {
    $('#mybody').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
Inner HTML * 1000
var t = document.getElementById('mybody');
for (var i = 0; i < 1000; ++i) {
  t.innerHTML += "<tr><td>" + i + "</td></tr>";
}
pending…
Inner HTML * 1
var t = document.getElementById('mybody');
var s = '';
for (var i = 0; i < 1000; ++i) {
  s += "<tr><td>" + i + "</td></tr>";
}
t.innerHTML = s;
pending…
.append inline
var $t = $('#mybody');
for (var i = 0; i < 1000; ++i) {
  var $td = $('<td>', {text: i});
  var $tr = $('<tr>');
  $td.appendTo($tr);
  $tr.appendTo($t);
}
pending…
.append outside
var $t = $('<tbody>');
for (var i = 0; i < 1000; ++i) {
  var $td = $('<td>', {text: i});
  var $tr = $('<tr>');
  $td.appendTo($tr);
  $tr.appendTo($t);
}
$('#mybody').replaceWith($t);
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. Here’s a list of current revisions for this page:

0 comments

Add a comment