DOM Table Generation

JavaScript performance comparison

Test case created by Matt McDonald

Info

Testing DOM table generation speed with various methods.

Preparation code

<style>
.hidden
{
        display: none;
}
</style>
<div class="hidden" id="container"></div>
<script>
Benchmark.prototype.setup = function() {
    function generateTable ()
    {
        var table = document.createElement("table"),
        body = document.createElement("tbody"),
        row = document.createElement("tr"),
        cell = document.createElement("td");
        row.appendChild(cell);
        body.appendChild(row);
        table.appendChild(body);
        return table;
    }
    var container = document.getElementById("container");
    function generateString ()
    {
        var string = "<table>";
        string += "\r\t<tbody>";
        string += "\r\t\t<tr>";
        string += "\r\t\t\t<td></td>";
        string += "\r\t\t</tr>";
        string += "\r\t</tbody>";
        string += "\r</table>";
        return string;
    }
};
</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
innerHTML
container.innerHTML = generateString();
container.innerHTML = "";
pending…
createElement
var table = generateTable();
container.appendChild(table);
container.removeChild(table);
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