C
Christopher Benson-Manica
Why is building a table with the DOM slower than using an array? IOW,
why is
var table=document.createDocumentFragment();
for( var i=0; i < 4000; i++ ) {
tr=table.insertRow( table.rows.length );
td=tr.appendChild( document.createElement('td') );
td.appendChild( 'foo' );
}
someElement.appendChild( table );
much slower than
var table[];
table.push( "<table>" );
for( var i=0; i < 4000; i++ ) {
table.push( "<tr>" );
table.push( "<td>foo</td>" );
table.push( "</tr>" );
}
table.push( "</table>" );
document.writeln( table.join('') ); // thanks again for the tip!!
? Am I doing something inadvisable with the document object?
why is
var table=document.createDocumentFragment();
for( var i=0; i < 4000; i++ ) {
tr=table.insertRow( table.rows.length );
td=tr.appendChild( document.createElement('td') );
td.appendChild( 'foo' );
}
someElement.appendChild( table );
much slower than
var table[];
table.push( "<table>" );
for( var i=0; i < 4000; i++ ) {
table.push( "<tr>" );
table.push( "<td>foo</td>" );
table.push( "</tr>" );
}
table.push( "</table>" );
document.writeln( table.join('') ); // thanks again for the tip!!
? Am I doing something inadvisable with the document object?